/*
 * SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 *
 * SPDX-License-Identifier: MulanPSL-2.0
 */
#![allow(
    unreachable_code,
    dead_code,
    mutable_transmutes,
    non_camel_case_types,
    non_snake_case,
    non_upper_case_globals,
    unused_assignments,
    unused_mut,
    unused_variables,
    clippy::never_loop
)]

#[macro_use]
mod common;
use crate::common::*;

mod alias;
mod audit;
mod base64;
mod defaults;
mod digestname;
mod filedigest;
mod gentime;
mod getdate;
mod gmtoff;
mod gram;
mod hexchar;
mod iolog_util;
mod linux_audit;
mod locale;
mod logging;
mod logwrap;
mod r#match;
mod match_addr;
mod match_command;
mod match_digest;
mod pwutil;
mod pwutil_impl;
mod rcstr;
mod redblack;
mod set_perms;
mod sudoers_debug;
mod timeout;
mod timestr;
mod toke;
mod toke_util;

#[link(name = "z")]
#[link(name = "audit")]
#[link(name = "utsudo_util")]
#[link(name = "util_variadic")]
#[link(name = "plugins_variadic")]
extern "C" {
    static mut sudoers_subsystem_ids: [libc::c_uint; 0];
    fn writev(__fd: libc::c_int, __iovec: *const iovec, __count: libc::c_int) -> ssize_t;
    fn lstat(path:*const libc::c_char,buf:*mut stat) -> libc::c_int;
    fn kill(__pid: __pid_t, __sig: libc::c_int) -> libc::c_int;
    static mut stdin: *mut FILE;
    static mut stdout: *mut FILE;
    static mut stderr: *mut FILE;
    fn fflush(__stream: *mut FILE) -> libc::c_int;
    fn fprintf(_: *mut FILE, _: *const libc::c_char, _: ...) -> libc::c_int;
    fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
    fn snprintf(
        _: *mut libc::c_char,
        _: libc::c_ulong,
        _: *const libc::c_char,
        _: ...
    ) -> libc::c_int;
    fn getc(__stream: *mut FILE) -> libc::c_int;
    fn putc(__c: libc::c_int, __stream: *mut FILE) -> libc::c_int;
    fn fputs(__s: *const libc::c_char, __stream: *mut FILE) -> libc::c_int;
    fn puts(__s: *const libc::c_char) -> libc::c_int;
    fn strtod(_: *const libc::c_char, _: *mut *mut libc::c_char) -> libc::c_double;
    fn calloc(_: libc::c_ulong, _: libc::c_ulong) -> *mut libc::c_void;
    fn reallocarray(__ptr: *mut libc::c_void, __nmemb: size_t, __size: size_t)
        -> *mut libc::c_void;
    fn free(_: *mut libc::c_void);
    fn exit(_: libc::c_int) -> !;
    fn getenv(__name: *const libc::c_char) -> *mut libc::c_char;
    fn qsort(__base: *mut libc::c_void, __nmemb: size_t, __size: size_t, __compar: __compar_fn_t);
    fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int;
    fn strncmp(_: *const libc::c_char, _: *const libc::c_char, _: libc::c_ulong) -> libc::c_int;
    fn strdup(_: *const libc::c_char) -> *mut libc::c_char;
    fn strcspn(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_ulong;
    fn strtok_r(
        __s: *mut libc::c_char,
        __delim: *const libc::c_char,
        __save_ptr: *mut *mut libc::c_char,
    ) -> *mut libc::c_char;
    fn strlen(_: *const libc::c_char) -> libc::c_ulong;
    fn strerror(_: libc::c_int) -> *mut libc::c_char;
    fn memchr(_: *const libc::c_void, _: libc::c_int, _: libc::c_ulong) -> *mut libc::c_void;
    fn read(__fd: libc::c_int, __buf: *mut libc::c_void, __nbytes: size_t) -> ssize_t;
    fn write(__fd: libc::c_int, __buf: *const libc::c_void, __n: size_t) -> ssize_t;
    fn getpid() -> __pid_t;
    fn isatty(__fd: libc::c_int) -> libc::c_int;
    static mut optarg: *mut libc::c_char;
    static mut optind: libc::c_int;
    fn __ctype_b_loc() -> *mut *const libc::c_ushort;
    fn __errno_location() -> *mut libc::c_int;
    fn open(__file: *const libc::c_char, __oflag: libc::c_int, _: ...) -> libc::c_int;
    fn opendir(__name: *const libc::c_char) -> *mut DIR;
    fn closedir(__dirp: *mut DIR) -> libc::c_int;
    fn readdir(__dirp: *mut DIR) -> *mut dirent;
    fn regcomp(
        __preg: *mut regex_t,
        __pattern: *const libc::c_char,
        __cflags: libc::c_int,
    ) -> libc::c_int;
    fn regexec(
        __preg: *const regex_t,
        __String: *const libc::c_char,
        __nmatch: size_t,
        __pmatch: *mut regmatch_t,
        __eflags: libc::c_int,
    ) -> libc::c_int;
    fn regerror(
        __errcode: libc::c_int,
        __preg: *const regex_t,
        __errbuf: *mut libc::c_char,
        __errbuf_size: size_t,
    ) -> size_t;
    fn bindtextdomain(
        __domainname: *const libc::c_char,
        __dirname: *const libc::c_char,
    ) -> *mut libc::c_char;
    fn textdomain(__domainname: *const libc::c_char) -> *mut libc::c_char;
    fn dcgettext(
        __domainname: *const libc::c_char,
        __msgid: *const libc::c_char,
        __category: libc::c_int,
    ) -> *mut libc::c_char;
    fn setlocale(__category: libc::c_int, __locale: *const libc::c_char) -> *mut libc::c_char;
    fn localeconv() -> *mut lconv;
    fn sudo_strlcat(dst: *mut libc::c_char, src: *const libc::c_char, siz: size_t) -> size_t;
    fn sudo_strlcpy(dst: *mut libc::c_char, src: *const libc::c_char, siz: size_t) -> size_t;
    fn sudo_getprogname() -> *const libc::c_char;
    fn sudo_fatal_callback_register_v1(func: sudo_fatal_callback_t) -> libc::c_int;
    fn sudo_warn_gettext_v1(
        domainname: *const libc::c_char,
        msgid: *const libc::c_char,
    ) -> *mut libc::c_char;
    fn sudo_fatal_nodebug_v1(fmt: *const libc::c_char, _: ...) -> !;
    fn sudo_fatalx_nodebug_v1(fmt: *const libc::c_char, _: ...) -> !;
    fn sudo_warnx_nodebug_v1(fmt: *const libc::c_char, _: ...);
    fn gzread(file: gzFile, buf: voidp, len: libc::c_uint) -> libc::c_int;
    fn gzgets(file: gzFile, buf: *mut libc::c_char, len: libc::c_int) -> *mut libc::c_char;
    fn gzeof(file: gzFile) -> libc::c_int;
    fn gzopen(_: *const libc::c_char, _: *const libc::c_char) -> gzFile;
    fn adjust_delay(delay: *mut timespec, max_delay: *mut timespec, scale_factor: libc::c_double);
    fn free_log_info(li: *mut log_info);
    fn parse_logfile(logfile: *const libc::c_char) -> *mut log_info;
    fn parse_timing(
        buf: *const libc::c_char,
        delay: *mut timespec,
        timing: *mut timing_closure,
    ) -> bool;
    fn sudo_conf_read_v1(conf_file: *const libc::c_char, conf_types: libc::c_int) -> libc::c_int;
    fn sudo_conf_debug_files_v1(progname: *const libc::c_char) -> *mut sudo_conf_debug_file_list;
    fn sudo_debug_enter_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
    );
    fn sudo_debug_exit_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
    );
    fn sudo_debug_exit_bool_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
        ret: bool,
    );
    fn sudo_debug_exit_int_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
        ret: libc::c_int,
    );
    fn sudo_debug_exit_ptr_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
        ret: *const libc::c_void,
    );
    fn sudo_debug_exit_ssize_t_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
        ret: ssize_t,
    );
    fn sudo_debug_exit_str_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        subsys: libc::c_int,
        ret: *const libc::c_char,
    );
    fn sudo_debug_printf2_v1(
        func: *const libc::c_char,
        file: *const libc::c_char,
        line: libc::c_int,
        level: libc::c_int,
        fmt: *const libc::c_char,
        _: ...
    );
    fn sudo_debug_register_v1(
        program: *const libc::c_char,
        subsystems: *const *const libc::c_char,
        ids: *mut libc::c_uint,
        debug_files: *mut sudo_conf_debug_file_list,
    ) -> libc::c_int;
    fn sudo_ev_base_alloc_v1() -> *mut sudo_event_base;
    fn sudo_ev_base_free_v1(base: *mut sudo_event_base);
    fn sudo_ev_alloc_v1(
        fd: libc::c_int,
        events: libc::c_short,
        callback: sudo_ev_callback_t,
        closure: *mut libc::c_void,
    ) -> *mut sudo_event;
    fn sudo_ev_free_v1(ev: *mut sudo_event);
    fn sudo_ev_add_v2(
        head: *mut sudo_event_base,
        ev: *mut sudo_event,
        timo: *mut timespec,
        tohead: bool,
    ) -> libc::c_int;
    fn sudo_ev_del_v1(head: *mut sudo_event_base, ev: *mut sudo_event) -> libc::c_int;
    fn sudo_ev_dispatch_v1(head: *mut sudo_event_base) -> libc::c_int;
    fn sudo_ev_get_timeleft_v2(ev: *mut sudo_event, tv: *mut timespec) -> libc::c_int;
    fn sudo_ev_loopexit_v1(base: *mut sudo_event_base);
    fn sudo_ev_loopbreak_v1(base: *mut sudo_event_base);
    fn sudo_ev_got_break_v1(base: *mut sudo_event_base) -> bool;
    fn initprogname(_: *const libc::c_char);
    fn sudo_term_raw_v1(fd: libc::c_int, isig: libc::c_int) -> bool;
    fn sudo_term_restore_v1(fd: libc::c_int, flush: bool) -> bool;
    fn sudo_get_ttysize_v1(rowp: *mut libc::c_int, colp: *mut libc::c_int);
    fn getopt_long(
        ___argc: libc::c_int,
        ___argv: *const *mut libc::c_char,
        __shortopts: *const libc::c_char,
        __longopts: *const option,
        __longind: *mut libc::c_int,
    ) -> libc::c_int;
    fn get_timestr(_: time_t, _: libc::c_int) -> *mut libc::c_char;
    fn get_date(_: *mut libc::c_char) -> time_t;
}
pub type __uint32_t = libc::c_uint;
pub type __dev_t = libc::c_ulong;
pub type __uid_t = libc::c_uint;
pub type __gid_t = libc::c_uint;
pub type __ino_t = libc::c_ulong;
pub type __mode_t = libc::c_uint;
pub type __off_t = libc::c_long;
pub type __off64_t = libc::c_long;
pub type __pid_t = libc::c_int;
pub type __clock_t = libc::c_long;
pub type __time_t = libc::c_long;
pub type __blkcnt_t = libc::c_long;
pub type __ssize_t = libc::c_long;
pub type __syscall_slong_t = libc::c_long;
pub type __sig_atomic_t = libc::c_int;
pub type off64_t = __off64_t;
pub type ssize_t = __ssize_t;
pub type time_t = __time_t;
pub type size_t = libc::c_ulong;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct __sigset_t {
    pub __val: [libc::c_ulong; 16],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct iovec {
    pub iov_base: *mut libc::c_void,
    pub iov_len: size_t,
}

pub type sig_atomic_t = __sig_atomic_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub union sigval {
    pub sival_int: libc::c_int,
    pub sival_ptr: *mut libc::c_void,
}

pub type __sigval_t = sigval;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct siginfo_t {
    pub si_signo: libc::c_int,
    pub si_errno: libc::c_int,
    pub si_code: libc::c_int,
    pub __pad0: libc::c_int,
    pub _sifields: C2RustUnnamed,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed {
    pub _pad: [libc::c_int; 28],
    pub _kill: C2RustUnnamed_8,
    pub _timer: C2RustUnnamed_7,
    pub _rt: C2RustUnnamed_6,
    pub _sigchld: C2RustUnnamed_5,
    pub _sigfault: C2RustUnnamed_2,
    pub _sigpoll: C2RustUnnamed_1,
    pub _sigsys: C2RustUnnamed_0,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub _call_addr: *mut libc::c_void,
    pub _syscall: libc::c_int,
    pub _arch: libc::c_uint,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub si_band: libc::c_long,
    pub si_fd: libc::c_int,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_2 {
    pub si_addr: *mut libc::c_void,
    pub si_addr_lsb: libc::c_short,
    pub _bounds: C2RustUnnamed_3,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_3 {
    pub _addr_bnd: C2RustUnnamed_4,
    pub _pkey: __uint32_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_4 {
    pub _lower: *mut libc::c_void,
    pub _upper: *mut libc::c_void,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_5 {
    pub si_pid: __pid_t,
    pub si_uid: __uid_t,
    pub si_status: libc::c_int,
    pub si_utime: __clock_t,
    pub si_stime: __clock_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_6 {
    pub si_pid: __pid_t,
    pub si_uid: __uid_t,
    pub si_sigval: __sigval_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_7 {
    pub si_tid: libc::c_int,
    pub si_overrun: libc::c_int,
    pub si_sigval: __sigval_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_8 {
    pub si_pid: __pid_t,
    pub si_uid: __uid_t,
}

pub type __sighandler_t = Option<unsafe extern "C" fn(libc::c_int) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct sigaction {
    pub __sigaction_handler: C2RustUnnamed_9,
    pub sa_mask: __sigset_t,
    pub sa_flags: libc::c_int,
    pub sa_restorer: Option<unsafe extern "C" fn() -> ()>,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_9 {
    pub sa_handler: __sighandler_t,
    pub sa_sigaction:
        Option<unsafe extern "C" fn(libc::c_int, *mut siginfo_t, *mut libc::c_void) -> ()>,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct _IO_FILE {
    pub _flags: libc::c_int,
    pub _IO_read_ptr: *mut libc::c_char,
    pub _IO_read_end: *mut libc::c_char,
    pub _IO_read_base: *mut libc::c_char,
    pub _IO_write_base: *mut libc::c_char,
    pub _IO_write_ptr: *mut libc::c_char,
    pub _IO_write_end: *mut libc::c_char,
    pub _IO_buf_base: *mut libc::c_char,
    pub _IO_buf_end: *mut libc::c_char,
    pub _IO_save_base: *mut libc::c_char,
    pub _IO_backup_base: *mut libc::c_char,
    pub _IO_save_end: *mut libc::c_char,
    pub _markers: *mut _IO_marker,
    pub _chain: *mut _IO_FILE,
    pub _fileno: libc::c_int,
    pub _flags2: libc::c_int,
    pub _old_offset: __off_t,
    pub _cur_column: libc::c_ushort,
    pub _vtable_offset: libc::c_schar,
    pub _shortbuf: [libc::c_char; 1],
    pub _lock: *mut libc::c_void,
    pub _offset: __off64_t,
    pub _codecvt: *mut _IO_codecvt,
    pub _wide_data: *mut _IO_wide_data,
    pub _freeres_list: *mut _IO_FILE,
    pub _freeres_buf: *mut libc::c_void,
    pub __pad5: size_t,
    pub _mode: libc::c_int,
    pub _unused2: [libc::c_char; 20],
}
pub type _IO_lock_t = ();
pub type FILE = _IO_FILE;
pub type __compar_fn_t =
    Option<unsafe extern "C" fn(*const libc::c_void, *const libc::c_void) -> libc::c_int>;
pub type C2RustUnnamed_10 = libc::c_uint;
pub const _ISalnum: C2RustUnnamed_10 = 8;
pub const _ISpunct: C2RustUnnamed_10 = 4;
pub const _IScntrl: C2RustUnnamed_10 = 2;
pub const _ISblank: C2RustUnnamed_10 = 1;
pub const _ISgraph: C2RustUnnamed_10 = 32768;
pub const _ISprint: C2RustUnnamed_10 = 16384;
pub const _ISspace: C2RustUnnamed_10 = 8192;
pub const _ISxdigit: C2RustUnnamed_10 = 4096;
pub const _ISdigit: C2RustUnnamed_10 = 2048;
pub const _ISalpha: C2RustUnnamed_10 = 1024;
pub const _ISlower: C2RustUnnamed_10 = 512;
pub const _ISupper: C2RustUnnamed_10 = 256;
pub const LC_ALL: libc::c_int = 6;
pub const IOFD_STDOUT: libc::c_int = 1;
pub const IOFD_STDERR: libc::c_int = 2;
pub const IOFD_TTYOUT: libc::c_int = 4;
pub const IOFD_MAX: libc::c_int = 6;
pub const ENAMETOOLONG: libc::c_int = 36;
pub const EINVAL: libc::c_int = 22;
pub const INITIAL: libc::c_int = 0;
pub const NEW_NUMBER: libc::c_int = 1;
pub const NUMBER: libc::c_int = 2;
pub const GOTSIZE: libc::c_int = 4;
pub const READCHAR: libc::c_int = 16;
pub const EAGAIN: libc::c_int = 11;
pub const SUDO_EV_READ: libc::c_int = 2;
pub const LINE_MAX: libc::c_int = 2048;
pub const IO_EVENT_WINSIZE: libc::c_int = 5;
pub const IO_EVENT_SUSPEND: libc::c_int = 7;
pub const IO_EVENT_STDIN: libc::c_int = 0;
pub const IO_EVENT_STDOUT: libc::c_int = 1;
pub const IO_EVENT_STDERR: libc::c_int = 2;
pub const IO_EVENT_TTYIN: libc::c_int = 3;
pub const IO_EVENT_TTYOUT: libc::c_int = 4;
pub const SIGHUP: libc::c_int = 1;
pub const SIGINT: libc::c_int = 2;
pub const SIGQUIT: libc::c_int = 3;
pub const SIGTERM: libc::c_int = 15;
pub const SIGTSTP: libc::c_int = 20;
pub const PATH_MAX: libc::c_int = 4096;
pub const SUDO_EV_TIMEOUT: libc::c_int = 1;
pub const SUDO_EV_SIGNAL: libc::c_int = 16;
pub const ST_CWD: libc::c_int = 9;
pub const ST_PATTERN: libc::c_int = 4;

pub const ST_FROMDATE: libc::c_int = 7;
pub const ST_RUNASGROUP: libc::c_int = 6;
pub const ST_RUNASUSER: libc::c_int = 5;
pub const ST_TODATE: libc::c_int = 8;
pub const ST_TTY: libc::c_int = 2;
pub const ST_EXPR: libc::c_int = 1;
pub const ST_USER: libc::c_int = 3;
pub const REG_EXTENDED: libc::c_int = 1;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct dirent {
    pub d_ino: __ino_t,
    pub d_off: __off_t,
    pub d_reclen: libc::c_ushort,
    pub d_type: libc::c_uchar,
    pub d_name: [libc::c_char; 256],
}
pub type C2RustUnnamed_11 = libc::c_uint;
pub const DT_WHT: C2RustUnnamed_11 = 14;
pub const DT_SOCK: C2RustUnnamed_11 = 12;
pub const DT_LNK: C2RustUnnamed_11 = 10;
pub const DT_REG: C2RustUnnamed_11 = 8;
pub const DT_BLK: C2RustUnnamed_11 = 6;
pub const DT_DIR: C2RustUnnamed_11 = 4;
pub const DT_CHR: C2RustUnnamed_11 = 2;
pub const DT_FIFO: C2RustUnnamed_11 = 1;
pub const DT_UNKNOWN: C2RustUnnamed_11 = 0;
pub type DIR = __dirstream;
pub type __re_long_size_t = libc::c_ulong;
pub type reg_syntax_t = libc::c_ulong;
pub type C2RustUnnamed_12 = libc::c_int;
pub const _REG_ERPAREN: C2RustUnnamed_12 = 16;
pub const _REG_ESIZE: C2RustUnnamed_12 = 15;
pub const _REG_EEND: C2RustUnnamed_12 = 14;
pub const _REG_BADRPT: C2RustUnnamed_12 = 13;
pub const _REG_ESPACE: C2RustUnnamed_12 = 12;
pub const _REG_ERANGE: C2RustUnnamed_12 = 11;
pub const _REG_BADBR: C2RustUnnamed_12 = 10;
pub const _REG_EBRACE: C2RustUnnamed_12 = 9;
pub const _REG_EPAREN: C2RustUnnamed_12 = 8;
pub const _REG_EBRACK: C2RustUnnamed_12 = 7;
pub const _REG_ESUBREG: C2RustUnnamed_12 = 6;
pub const _REG_EESCAPE: C2RustUnnamed_12 = 5;
pub const _REG_ECTYPE: C2RustUnnamed_12 = 4;
pub const _REG_ECOLLATE: C2RustUnnamed_12 = 3;
pub const _REG_BADPAT: C2RustUnnamed_12 = 2;
pub const _REG_NOMATCH: C2RustUnnamed_12 = 1;
pub const _REG_NOERROR: C2RustUnnamed_12 = 0;
pub const _REG_ENOSYS: C2RustUnnamed_12 = -1;

#[derive(Copy, Clone, BitfieldStruct)]
#[repr(C)]
pub struct re_pattern_buffer {
    pub buffer: *mut re_dfa_t,
    pub allocated: __re_long_size_t,
    pub used: __re_long_size_t,
    pub syntax: reg_syntax_t,
    pub fastmap: *mut libc::c_char,
    pub translate: *mut libc::c_uchar,
    pub re_nsub: size_t,
    #[bitfield(name = "can_be_null", ty = "libc::c_uint", bits = "0..=0")]
    #[bitfield(name = "regs_allocated", ty = "libc::c_uint", bits = "1..=2")]
    #[bitfield(name = "fastmap_accurate", ty = "libc::c_uint", bits = "3..=3")]
    #[bitfield(name = "no_sub", ty = "libc::c_uint", bits = "4..=4")]
    #[bitfield(name = "not_bol", ty = "libc::c_uint", bits = "5..=5")]
    #[bitfield(name = "not_eol", ty = "libc::c_uint", bits = "6..=6")]
    #[bitfield(name = "newline_anchor", ty = "libc::c_uint", bits = "7..=7")]
    pub can_be_null_regs_allocated_fastmap_accurate_no_sub_not_bol_not_eol_newline_anchor: [u8; 1],
    #[bitfield(padding)]
    pub c2rust_padding: [u8; 7],
}
pub type regex_t = re_pattern_buffer;
pub type regoff_t = libc::c_int;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct regmatch_t {
    pub rm_so: regoff_t,
    pub rm_eo: regoff_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct lconv {
    pub decimal_point: *mut libc::c_char,
    pub thousands_sep: *mut libc::c_char,
    pub grouping: *mut libc::c_char,
    pub int_curr_symbol: *mut libc::c_char,
    pub currency_symbol: *mut libc::c_char,
    pub mon_decimal_point: *mut libc::c_char,
    pub mon_thousands_sep: *mut libc::c_char,
    pub mon_grouping: *mut libc::c_char,
    pub positive_sign: *mut libc::c_char,
    pub negative_sign: *mut libc::c_char,
    pub int_frac_digits: libc::c_char,
    pub frac_digits: libc::c_char,
    pub p_cs_precedes: libc::c_char,
    pub p_sep_by_space: libc::c_char,
    pub n_cs_precedes: libc::c_char,
    pub n_sep_by_space: libc::c_char,
    pub p_sign_posn: libc::c_char,
    pub n_sign_posn: libc::c_char,
    pub int_p_cs_precedes: libc::c_char,
    pub int_p_sep_by_space: libc::c_char,
    pub int_n_cs_precedes: libc::c_char,
    pub int_n_sep_by_space: libc::c_char,
    pub int_p_sign_posn: libc::c_char,
    pub int_n_sign_posn: libc::c_char,
}
pub type sudo_fatal_callback_t = Option<unsafe extern "C" fn() -> ()>;
pub type voidp = *mut libc::c_void;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct gzFile_s {
    pub have: libc::c_uint,
    pub next: *mut libc::c_uchar,
    pub pos: off64_t,
}
pub type gzFile = *mut gzFile_s;

#[derive(Copy, Clone)]
#[repr(C)]
pub union io_fd {
    pub f: *mut FILE,
    pub g: gzFile,
    pub v: *mut libc::c_void,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct log_info {
    pub cwd: *mut libc::c_char,
    pub user: *mut libc::c_char,
    pub runas_user: *mut libc::c_char,
    pub runas_group: *mut libc::c_char,
    pub tty: *mut libc::c_char,
    pub cmd: *mut libc::c_char,
    pub tstamp: time_t,
    pub rows: libc::c_int,
    pub cols: libc::c_int,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct timing_closure {
    pub decimal: *const libc::c_char,
    pub max_delay: *mut timespec,
    pub fd: io_fd,
    pub event: libc::c_int,
    pub u: C2RustUnnamed_13,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_13 {
    pub winsize: C2RustUnnamed_14,
    pub nbytes: size_t,
    pub signo: libc::c_int,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_14 {
    pub rows: libc::c_int,
    pub cols: libc::c_int,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct io_log_file {
    pub enabled: bool,
    pub suffix: *const libc::c_char,
    pub fd: io_fd,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_debug_file {
    pub entries: C2RustUnnamed_15,
    pub debug_file: *mut libc::c_char,
    pub debug_flags: *mut libc::c_char,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_15 {
    pub tqe_next: *mut sudo_debug_file,
    pub tqe_prev: *mut *mut sudo_debug_file,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_conf_debug_file_list {
    pub tqh_first: *mut sudo_debug_file,
    pub tqh_last: *mut *mut sudo_debug_file,
}
pub type sudo_ev_callback_t =
    Option<unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> ()>;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_event {
    pub entries: C2RustUnnamed_18,
    pub active_entries: C2RustUnnamed_17,
    pub timeouts_entries: C2RustUnnamed_16,
    pub base: *mut sudo_event_base,
    pub fd: libc::c_int,
    pub events: libc::c_short,
    pub revents: libc::c_short,
    pub flags: libc::c_short,
    pub pfd_idx: libc::c_short,
    pub callback: sudo_ev_callback_t,
    pub timeout: timespec,
    pub closure: *mut libc::c_void,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_event_base {
    pub events: sudo_event_list,
    pub active: sudo_event_list,
    pub timeouts: sudo_event_list,
    pub signal_event: sudo_event,
    pub signals: [sudo_event_list; 65],
    pub orig_handlers: [*mut sigaction; 65],
    pub siginfo: [*mut siginfo_t; 65],
    pub signal_pending: [sig_atomic_t; 65],
    pub signal_caught: sig_atomic_t,
    pub num_handlers: libc::c_int,
    pub signal_pipe: [libc::c_int; 2],
    pub pfds: *mut pollfd,
    pub pfd_max: libc::c_int,
    pub pfd_high: libc::c_int,
    pub pfd_free: libc::c_int,
    pub flags: libc::c_uint,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct sudo_event_list {
    pub tqh_first: *mut sudo_event,
    pub tqh_last: *mut *mut sudo_event,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_16 {
    pub tqe_next: *mut sudo_event,
    pub tqe_prev: *mut *mut sudo_event,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_17 {
    pub tqe_next: *mut sudo_event,
    pub tqe_prev: *mut *mut sudo_event,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_18 {
    pub tqe_next: *mut sudo_event,
    pub tqe_prev: *mut *mut sudo_event,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct option {
    pub name: *const libc::c_char,
    pub has_arg: libc::c_int,
    pub flag: *mut libc::c_int,
    pub val: libc::c_int,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct replay_closure {
    pub evbase: *mut sudo_event_base,
    pub delay_ev: *mut sudo_event,
    pub keyboard_ev: *mut sudo_event,
    pub output_ev: *mut sudo_event,
    pub sighup_ev: *mut sudo_event,
    pub sigint_ev: *mut sudo_event,
    pub sigquit_ev: *mut sudo_event,
    pub sigterm_ev: *mut sudo_event,
    pub sigtstp_ev: *mut sudo_event,
    pub timing: timing_closure,
    pub interactive: bool,
    pub suspend_wait: bool,
    pub iobuf: io_buffer,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct io_buffer {
    pub len: libc::c_uint,
    pub off: libc::c_uint,
    pub toread: libc::c_uint,
    pub lastc: libc::c_int,
    pub buf: [libc::c_char; 65536],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct search_node_list {
    pub stqh_first: *mut search_node,
    pub stqh_last: *mut *mut search_node,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct search_node {
    pub entries: C2RustUnnamed_20,
    pub type_0: libc::c_char,
    pub negated: bool,
    pub or: bool,
    pub u: C2RustUnnamed_19,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_19 {
    pub cmdre: regex_t,
    pub tstamp: time_t,
    pub cwd: *mut libc::c_char,
    pub tty: *mut libc::c_char,
    pub user: *mut libc::c_char,
    pub runas_group: *mut libc::c_char,
    pub runas_user: *mut libc::c_char,
    pub expr: search_node_list,
    pub ptr: *mut libc::c_void,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_20 {
    pub stqe_next: *mut search_node,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct getsize_closure {
    pub nums: [libc::c_int; 2],
    pub nums_depth: libc::c_int,
    pub nums_maxdepth: libc::c_int,
    pub state: libc::c_int,
    pub cp: *const libc::c_char,
    pub ev: *mut sudo_event,
    pub timeout: timespec,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct term_names {
    pub name: *const libc::c_char,
    pub len: libc::c_uint,
}

#[macro_export]
macro_rules! IS_IDLOG {
    ($s:expr) => {
        (isalnum!(*$s.offset(0 as isize) as libc::c_uchar as libc::c_int as isize) != 0
            && isalnum!(*$s.offset(1 as isize) as libc::c_uchar as libc::c_int as isize) != 0
            && *$s.offset(2 as libc::c_int as isize) as libc::c_int == '/' as i32
            && isalnum!(*$s.offset(3 as isize) as libc::c_uchar as libc::c_int as isize) != 0
            && isalnum!(*$s.offset(4 as isize) as libc::c_uchar as libc::c_int as isize) != 0
            && *$s.offset(5 as libc::c_int as isize) as libc::c_int == '/' as i32
            && isalnum!(*$s.offset(6 as isize) as libc::c_uchar as libc::c_int as isize) != 0
            && isalnum!(*$s.offset(7 as isize) as libc::c_uchar as libc::c_int as isize) != 0
            && *$s.offset(8 as libc::c_int as isize) as libc::c_int == '/' as i32
            && *$s.offset(9 as libc::c_int as isize) as libc::c_int == 'l' as i32
            && *$s.offset(10 as libc::c_int as isize) as libc::c_int == 'o' as i32
            && *$s.offset(11 as libc::c_int as isize) as libc::c_int == 'g' as i32
            && *$s.offset(12 as libc::c_int as isize) as libc::c_int == '\0' as i32)
    };
}

#[inline]
unsafe extern "C" fn getchar() -> libc::c_int {
    getc(stdin)
}
#[inline]
unsafe extern "C" fn putchar(mut __c: libc::c_int) -> libc::c_int {
    putc(__c, stdout)
}
static mut io_log_files: [io_log_file; 7] = [
    {
        io_log_file {
            enabled: 0 as libc::c_int != 0,
            suffix: b"/stdin\0" as *const u8 as *const libc::c_char,
            fd: io_fd {
                f: 0 as *const FILE as *mut FILE,
            },
        }
        //init
    },
    {
        io_log_file {
            enabled: 0 as libc::c_int != 0,
            suffix: b"/stdout\0" as *const u8 as *const libc::c_char,
            fd: io_fd {
                f: 0 as *const FILE as *mut FILE,
            },
        }
        //init
    },
    {
        io_log_file {
            enabled: 0 as libc::c_int != 0,
            suffix: b"/stderr\0" as *const u8 as *const libc::c_char,
            fd: io_fd {
                f: 0 as *const FILE as *mut FILE,
            },
        }
        //init
    },
    {
        io_log_file {
            enabled: 0 as libc::c_int != 0,
            suffix: b"/ttyin\0" as *const u8 as *const libc::c_char,
            fd: io_fd {
                f: 0 as *const FILE as *mut FILE,
            },
        }
        //init
    },
    {
        io_log_file {
            enabled: 0 as libc::c_int != 0,
            suffix: b"/ttyout\0" as *const u8 as *const libc::c_char,
            fd: io_fd {
                f: 0 as *const FILE as *mut FILE,
            },
        }
        //init
    },
    {
        io_log_file {
            enabled: 1 as libc::c_int != 0,
            suffix: b"/timing\0" as *const u8 as *const libc::c_char,
            fd: io_fd {
                f: 0 as *const FILE as *mut FILE,
            },
        }
        //init
    },
    {
        io_log_file {
            enabled: 0 as libc::c_int != 0,
            suffix: 0 as *const libc::c_char,
            fd: io_fd {
                f: 0 as *const FILE as *mut FILE,
            },
        }
        //init
    },
];
static mut search_expr: search_node_list = search_node_list {
    // direct used
    stqh_first: 0 as *const search_node as *mut search_node,
    stqh_last: 0 as *const *mut search_node as *mut *mut search_node,
};
static mut speed_factor: libc::c_double = 1.0f64; //direct used
static mut session_dir: *const libc::c_char = //direct used
    b"/var/log/utsudo-io\0" as *const u8 as *const libc::c_char;
static mut terminal_can_resize: bool = false;
static mut terminal_was_resized: bool = false;
static mut terminal_rows: libc::c_int = 0;
static mut terminal_cols: libc::c_int = 0;
static mut ttyfd: libc::c_int = -(1 as libc::c_int);
static mut short_opts: [libc::c_char; 15] =
    unsafe { *::core::mem::transmute::<&[u8; 15], &[libc::c_char; 15]>(b"d:f:hlm:nRSs:V\0") };
static mut long_opts: [option; 11] = [
    {
        option {
            name: b"directory\0" as *const u8 as *const libc::c_char,
            has_arg: 1 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'd' as i32,
        }
        //init
    },
    {
        option {
            name: b"filter\0" as *const u8 as *const libc::c_char,
            has_arg: 1 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'f' as i32,
        }
        //init
    },
    {
        option {
            name: b"help\0" as *const u8 as *const libc::c_char,
            has_arg: 0 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'h' as i32,
        }
        //init
    },
    {
        option {
            name: b"list\0" as *const u8 as *const libc::c_char,
            has_arg: 0 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'l' as i32,
        }
        //init
    },
    {
        option {
            name: b"max-wait\0" as *const u8 as *const libc::c_char,
            has_arg: 1 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'm' as i32,
        }
        //init
    },
    {
        option {
            name: b"non-interactive\0" as *const u8 as *const libc::c_char,
            has_arg: 0 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'n' as i32,
        }
        //init
    },
    {
        option {
            name: b"no-resize\0" as *const u8 as *const libc::c_char,
            has_arg: 0 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'R' as i32,
        }
        //init
    },
    {
        option {
            name: b"suspend-wait\0" as *const u8 as *const libc::c_char,
            has_arg: 0 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'S' as i32,
        }
        //init
    },
    {
        option {
            name: b"speed\0" as *const u8 as *const libc::c_char,
            has_arg: 1 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 's' as i32,
        }
        //init
    },
    {
        option {
            name: b"version\0" as *const u8 as *const libc::c_char,
            has_arg: 0 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: 'V' as i32,
        }
        //init
    },
    {
        option {
            name: 0 as *const libc::c_char,
            has_arg: 0 as libc::c_int,
            flag: 0 as *const libc::c_int as *mut libc::c_int,
            val: '\0' as i32,
        }
        //init
    },
];
//end direct used

fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> libc::c_int {
    let mut current_block: u64; //can remove
    let mut ch: libc::c_int = 0;
    let mut i: libc::c_int = 0;
    let mut plen: libc::c_int = 0;
    let mut exitcode: libc::c_int = 0 as libc::c_int;
    let mut def_filter: bool = 1 as libc::c_int != 0;
    let mut listonly: bool = 0 as libc::c_int != 0;
    let mut interactive: bool = 1 as libc::c_int != 0;
    let mut suspend_wait: bool = 0 as libc::c_int != 0;
    let mut resize: bool = 1 as libc::c_int != 0;
    let mut decimal: *const libc::c_char = std::ptr::null::<libc::c_char>();
    let mut id: *const libc::c_char = std::ptr::null::<libc::c_char>();
    let mut user: *const libc::c_char = std::ptr::null::<libc::c_char>();
    let mut pattern: *const libc::c_char = std::ptr::null::<libc::c_char>();
    let mut tty: *const libc::c_char = std::ptr::null::<libc::c_char>();
    let mut cp: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut ep: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut path: [libc::c_char; 4096] = [0; 4096];
    let mut li: *mut log_info = std::ptr::null_mut::<log_info>();
    let mut max_delay_storage: timespec = timespec {
        tv_sec: 0,
        tv_nsec: 0,
    };
    let mut max_delay: *mut timespec = std::ptr::null_mut::<timespec>();
    let mut dval: libc::c_double = 0.;
    let sudo_debug_subsys_tmp: libc::c_int = (7 as libc::c_int) << 6 as libc::c_int;
    unsafe {
        debug_decl!(SUDOERS_DEBUG_MAIN!());

        initprogname(if argc > 0 as libc::c_int {
            *argv.offset(0 as libc::c_int as isize) as *const libc::c_char
        } else {
            b"sudoreplay\0" as *const u8 as *const libc::c_char
        });
        setlocale(
            LC_ALL as libc::c_int,
            b"\0" as *const u8 as *const libc::c_char,
        );
        decimal = (*localeconv()).decimal_point;
        bindtextdomain(
            b"sudoers\0" as *const u8 as *const libc::c_char,
            b"/usr/share/locale\0" as *const u8 as *const libc::c_char,
        );
        textdomain(b"sudoers\0" as *const u8 as *const libc::c_char);

        sudo_fatal_callback_register_v1(Some(sudoreplay_cleanup as unsafe extern "C" fn() -> ()));

        if sudo_conf_read_v1(std::ptr::null::<libc::c_char>(), 0x1 as libc::c_int)
            == -(1 as libc::c_int)
        {
            exit(1 as libc::c_int);
        }
        sudo_debug_register_v1(
            sudo_getprogname(),
            std::ptr::null::<*const libc::c_char>(),
            std::ptr::null_mut::<libc::c_uint>(),
            sudo_conf_debug_files_v1(sudo_getprogname()),
        );

        'done: loop {
            loop {
                ch = getopt_long(
                    argc,
                    argv as *const *mut libc::c_char,
                    short_opts.as_ptr(),
                    long_opts.as_mut_ptr(),
                    std::ptr::null_mut::<libc::c_int>(),
                );
                if ch == -(1 as libc::c_int) {
                    break;
                }
                match ch as u8 as char {
                    'd' => {
                        session_dir = optarg;
                    }
                    'f' => {
                        def_filter = 0 as libc::c_int != 0;
                        cp = strtok_r(optarg, b",\0" as *const u8 as *const libc::c_char, &mut ep);
                        while !cp.is_null() {
                            if strcmp(cp, b"stdin\0" as *const u8 as *const libc::c_char)
                                == 0 as libc::c_int
                            {
                                io_log_files[0 as libc::c_int as usize].enabled =
                                    1 as libc::c_int != 0;
                            } else if strcmp(cp, b"stdout\0" as *const u8 as *const libc::c_char)
                                == 0 as libc::c_int
                            {
                                io_log_files[1 as libc::c_int as usize].enabled =
                                    1 as libc::c_int != 0;
                            } else if strcmp(cp, b"stderr\0" as *const u8 as *const libc::c_char)
                                == 0 as libc::c_int
                            {
                                io_log_files[2 as libc::c_int as usize].enabled =
                                    1 as libc::c_int != 0;
                            } else if strcmp(cp, b"ttyin\0" as *const u8 as *const libc::c_char)
                                == 0 as libc::c_int
                            {
                                io_log_files[3 as libc::c_int as usize].enabled =
                                    1 as libc::c_int != 0;
                            } else if strcmp(cp, b"ttyout\0" as *const u8 as *const libc::c_char)
                                == 0 as libc::c_int
                            {
                                io_log_files[4 as libc::c_int as usize].enabled =
                                    1 as libc::c_int != 0;
                            } else {
                                sudo_fatalx!(
                                    b"invalid failter option: %s\0" as *const u8
                                        as *const libc::c_char,
                                    optarg,
                                );
                            }
                            cp = strtok_r(
                                std::ptr::null_mut::<libc::c_char>(),
                                b",\0" as *const u8 as *const libc::c_char,
                                &mut ep,
                            );
                        }
                    }
                    'h' => {
                        help();
                    }
                    'l' => {
                        listonly = 1 as libc::c_int != 0;
                    }
                    'm' => {
                        *__errno_location() = 0 as libc::c_int;
                        dval = strtod(optarg, &mut ep);
                        if *ep as libc::c_int != '\0' as i32
                            || *__errno_location() != 0 as libc::c_int
                        {
                            sudo_fatalx!(
                                b"invalid max wait: %s\0" as *const u8 as *const libc::c_char,
                                optarg,
                            );
                        }
                        if dval <= 0.0f64 {
                            max_delay_storage.tv_nsec = 0 as libc::c_int as __syscall_slong_t;
                            max_delay_storage.tv_sec = max_delay_storage.tv_nsec;
                        } else {
                            max_delay_storage.tv_sec = dval as __time_t;
                            max_delay_storage.tv_nsec = ((dval
                                - max_delay_storage.tv_sec as libc::c_double)
                                * 1000000000.0f64)
                                as __syscall_slong_t;
                        }
                        max_delay = &mut max_delay_storage;
                    }
                    'n' => {
                        interactive = 0 as libc::c_int != 0;
                    }
                    'R' => {
                        resize = 0 as libc::c_int != 0;
                    }
                    'S' => {
                        suspend_wait = 1 as libc::c_int != 0;
                    }
                    's' => {
                        *__errno_location() = 0 as libc::c_int;
                        speed_factor = strtod(optarg, &mut ep);
                        if *ep as libc::c_int != '\0' as i32
                            || *__errno_location() != 0 as libc::c_int
                        {
                            sudo_fatalx!(
                                b"invalid speed factor: %s\0" as *const u8 as *const libc::c_char,
                                optarg,
                            );
                        }
                    }
                    'V' => {
                        printf(
                            dcgettext(
                                std::ptr::null::<libc::c_char>(),
                                b"%s version %s\n\0" as *const u8 as *const libc::c_char,
                                5 as libc::c_int,
                            ),
                            sudo_getprogname(),
                            b"0.1.0\0" as *const u8 as *const libc::c_char,
                        );
                        break 'done;
                    }
                    _ => {
                        usage(1 as libc::c_int);
                    }
                } //match
            } //while

            argc -= optind;
            argv = argv.offset(optind as isize);

            if listonly {
                exitcode = list_sessions(argc, argv, pattern, user, tty);
                break 'done;
            }

            if argc != 1 as libc::c_int {
                usage(1 as libc::c_int);
            }

            if def_filter {
                io_log_files[IOFD_STDOUT as libc::c_int as usize].enabled = 1 as libc::c_int != 0;
                io_log_files[IOFD_STDERR as libc::c_int as usize].enabled = 1 as libc::c_int != 0;
                io_log_files[IOFD_TTYOUT as libc::c_int as usize].enabled = 1 as libc::c_int != 0;
            }
            id = *argv.offset(0 as libc::c_int as isize);

            if *(*__ctype_b_loc()).offset(
                *id.offset(0 as libc::c_int as isize) as libc::c_uchar as libc::c_int as isize
            ) as libc::c_int
                & _ISalnum as libc::c_int as libc::c_ushort as libc::c_int
                != 0
                && *(*__ctype_b_loc()).offset(
                    *id.offset(1 as libc::c_int as isize) as libc::c_uchar as libc::c_int as isize,
                ) as libc::c_int
                    & _ISalnum as libc::c_int as libc::c_ushort as libc::c_int
                    != 0
                && *(*__ctype_b_loc()).offset(
                    *id.offset(2 as libc::c_int as isize) as libc::c_uchar as libc::c_int as isize,
                ) as libc::c_int
                    & _ISalnum as libc::c_int as libc::c_ushort as libc::c_int
                    != 0
                && *(*__ctype_b_loc()).offset(
                    *id.offset(3 as libc::c_int as isize) as libc::c_uchar as libc::c_int as isize,
                ) as libc::c_int
                    & _ISalnum as libc::c_int as libc::c_ushort as libc::c_int
                    != 0
                && *(*__ctype_b_loc()).offset(
                    *id.offset(4 as libc::c_int as isize) as libc::c_uchar as libc::c_int as isize,
                ) as libc::c_int
                    & _ISalnum as libc::c_int as libc::c_ushort as libc::c_int
                    != 0
                && *(*__ctype_b_loc()).offset(
                    *id.offset(5 as libc::c_int as isize) as libc::c_uchar as libc::c_int as isize,
                ) as libc::c_int
                    & _ISalnum as libc::c_int as libc::c_ushort as libc::c_int
                    != 0
                && *id.offset(6 as libc::c_int as isize) as libc::c_int == '\0' as i32
            {
                plen = snprintf(
                    path.as_mut_ptr(),
                    ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong,
                    b"%s/%.2s/%.2s/%.2s/timing\0" as *const u8 as *const libc::c_char,
                    session_dir,
                    id,
                    &*id.offset(2 as libc::c_int as isize) as *const libc::c_char,
                    &*id.offset(4 as libc::c_int as isize) as *const libc::c_char,
                );
                if plen < 0 as libc::c_int
                    || plen as libc::c_long
                        >= ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong
                            as ssize_t
                {
                    sudo_fatalx!(
                        b"%s/%.2s/%.2s/%.2s/timing: %s\0" as *const u8 as *const libc::c_char,
                        session_dir,
                        id,
                        &*id.offset(2 as libc::c_int as isize) as *const libc::c_char,
                        &*id.offset(4 as libc::c_int as isize) as *const libc::c_char,
                        strerror(ENAMETOOLONG as libc::c_int),
                    );
                }
            } else if *id.offset(0 as libc::c_int as isize) as libc::c_int == '/' as i32 {
                plen = snprintf(
                    path.as_mut_ptr(),
                    ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong,
                    b"%s/timing\0" as *const u8 as *const libc::c_char,
                    id,
                );
                if plen < 0 as libc::c_int
                    || plen as libc::c_long
                        >= ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong
                            as ssize_t
                {
                    sudo_fatalx!(
                        b"%s/timing: %s\0" as *const u8 as *const libc::c_char,
                        id,
                        strerror(ENAMETOOLONG as libc::c_int),
                    );
                }
            } else {
                plen = snprintf(
                    path.as_mut_ptr(),
                    ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong,
                    b"%s/%s/timing\0" as *const u8 as *const libc::c_char,
                    session_dir,
                    id,
                );
                if plen < 0 as libc::c_int
                    || plen as libc::c_long
                        >= ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong
                            as ssize_t
                {
                    sudo_fatalx!(
                        b"%s/%s/timing: %s\0" as *const u8 as *const libc::c_char,
                        session_dir,
                        id,
                        strerror(ENAMETOOLONG as libc::c_int),
                    );
                }
            }
            plen -= 7 as libc::c_int;

            i = 0 as libc::c_int;
            while i < IOFD_MAX as libc::c_int {
                if open_io_fd(
                    path.as_mut_ptr(),
                    plen,
                    &mut *io_log_files.as_mut_ptr().offset(i as isize),
                ) == -(1 as libc::c_int)
                {
                    sudo_fatal!(
                        b"unable to open %s\0" as *const u8 as *const libc::c_char,
                        path
                    );
                }
                i += 1;
            }

            path[plen as usize] = '\0' as i32 as libc::c_char;
            sudo_strlcat(
                path.as_mut_ptr(),
                b"/log\0" as *const u8 as *const libc::c_char,
                ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong,
            );

            li = parse_logfile(path.as_mut_ptr());
            if li.is_null() {
                exit(1 as libc::c_int);
            }
            printf(
                dcgettext(
                    std::ptr::null::<libc::c_char>(),
                    b"Replaying utsudo session: %s\0" as *const u8 as *const libc::c_char,
                    5 as libc::c_int,
                ),
                (*li).cmd,
            );
            if isatty(0 as libc::c_int) == 0 || isatty(1 as libc::c_int) == 0 {
                interactive = 0 as libc::c_int != 0;
            }
            setup_terminal(li, interactive, resize);
            putchar('\r' as i32);
            putchar('\n' as i32);
            free_log_info(li);
            li = std::ptr::null_mut::<log_info>();

            exitcode = replay_session(max_delay, decimal, interactive, suspend_wait);
            restore_terminal_size();
            sudo_term_restore_v1(ttyfd, 1 as libc::c_int != 0);

            break 'done;
        }

        debug_return_int!(exitcode);
        exit(exitcode);
    }
}

fn io_log_read(mut ifd: io_fd, mut buf: *mut libc::c_char, mut nbytes: size_t) -> ssize_t {
    let mut nread: ssize_t = 0;
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        if nbytes > 2147483647 as libc::c_int as libc::c_ulong {
            *__errno_location() = EINVAL as libc::c_int;
            debug_return_ssize_t!(-1);
        }
        nread = gzread(ifd.g, buf as voidp, nbytes as libc::c_uint) as ssize_t;
        debug_return_ssize_t!(nread);
    }
}

fn io_log_eof(mut ifd: io_fd) -> libc::c_int {
    let mut ret: libc::c_int = 0;
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());
        ret = gzeof(ifd.g);
        debug_return_int!(ret);
    }
}

fn io_log_gets(
    mut ifd: io_fd,
    mut buf: *mut libc::c_char,
    mut nbytes: size_t,
) -> *mut libc::c_char {
    let mut str: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        str = gzgets(ifd.g, buf, nbytes as libc::c_int);
        debug_return_str!(str);
    }
}

#[no_mangle]
pub static mut compatible_terms: [term_names; 10] = [
    {
        term_names {
            name: b"Eterm\0" as *const u8 as *const libc::c_char,
            len: 5 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: b"aterm\0" as *const u8 as *const libc::c_char,
            len: 5 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: b"dtterm\0" as *const u8 as *const libc::c_char,
            len: 6 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: b"gnome\0" as *const u8 as *const libc::c_char,
            len: 5 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: b"konsole\0" as *const u8 as *const libc::c_char,
            len: 7 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: b"kvt\0\0" as *const u8 as *const libc::c_char,
            len: 4 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: b"mlterm\0" as *const u8 as *const libc::c_char,
            len: 6 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: b"rxvt\0" as *const u8 as *const libc::c_char,
            len: 4 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: b"xterm\0" as *const u8 as *const libc::c_char,
            len: 5 as libc::c_int as libc::c_uint,
        }
        //init
    },
    {
        term_names {
            name: 0 as *const libc::c_char,
            len: 0 as libc::c_int as libc::c_uint,
        }
        //init
    },
];

unsafe extern "C" fn getsize_cb(
    mut fd: libc::c_int,
    mut what: libc::c_int,
    mut v: *mut libc::c_void,
) {
    let mut current_block: u64;
    let mut gc: *mut getsize_closure = v as *mut getsize_closure;
    let mut ch: libc::c_uchar = '\0' as i32 as libc::c_uchar;
    debug_decl!(SUDOERS_DEBUG_UTIL!());

    'done: loop {
        loop {
            //for
            if *((*gc).cp).offset(0 as libc::c_int as isize) as libc::c_int == '\0' as i32 {
                (*gc).state = GOTSIZE as libc::c_int;
                break 'done;
            }
            if (*gc).state & READCHAR as libc::c_int != 0 {
                let mut nread: ssize_t = read(
                    ttyfd,
                    &mut ch as *mut libc::c_uchar as *mut libc::c_void,
                    1 as libc::c_int as size_t,
                );
                match nread {
                    -1 => {
                        if *__errno_location() == 11 as libc::c_int {
                            if sudo_ev_add_v2(
                                std::ptr::null_mut::<sudo_event_base>(),
                                (*gc).ev,
                                &mut (*gc).timeout,
                                0 as libc::c_int != 0,
                            ) == -(1 as libc::c_int)
                            {
                                sudo_fatal!(
                                    b"unable to add event to queue\0" as *const u8
                                        as *const libc::c_char,
                                );
                            }
                            break 'done;
                        }
                    }
                    0 => {
                        break 'done;
                    }
                    _ => {
                        (*gc).state &= !(0x10 as libc::c_int);
                    }
                }
            }

            match (*gc).state {
                0 => {
                    if ch as libc::c_int == 0o233 as libc::c_int
                        && *((*gc).cp).offset(0 as libc::c_int as isize) as libc::c_int
                            == '\u{1b}' as i32
                    {
                        ch = '[' as i32 as libc::c_uchar;
                        (*gc).cp = ((*gc).cp).offset(1);
                    }
                    if *((*gc).cp).offset(0 as libc::c_int as isize) as libc::c_int == '%' as i32
                        && *((*gc).cp).offset(1 as libc::c_int as isize) as libc::c_int
                            == 'd' as i32
                    {
                        (*gc).state = 0x1 as libc::c_int;
                        continue;
                    }
                    if *((*gc).cp).offset(0 as libc::c_int as isize) as libc::c_int
                        != ch as libc::c_int
                    {
                        sudo_debug_printf!(
                            SUDO_DEBUG_WARN | SUDO_DEBUG_LINENO,
                            b"got %d, expected %d\0" as *const u8 as *const libc::c_char,
                            ch as libc::c_int,
                            *((*gc).cp).offset(0 as libc::c_int as isize) as libc::c_int
                        );
                        break 'done;
                    }
                    sudo_debug_printf!(
                        SUDO_DEBUG_DEBUG | SUDO_DEBUG_LINENO,
                        b"got %d\0" as *const u8 as *const libc::c_char,
                        ch as libc::c_int
                    );
                    (*gc).state |= 0x10 as libc::c_int;
                    (*gc).cp = ((*gc).cp).offset(1);
                }
                1 | 2 => {
                    if (*gc).state == 1 {
                        sudo_debug_printf!(
                            SUDO_DEBUG_DEBUG | SUDO_DEBUG_LINENO,
                            b"parsing number\0" as *const u8 as *const libc::c_char
                        );
                        if *(*__ctype_b_loc()).offset(ch as libc::c_int as isize) as libc::c_int
                            & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int
                            == 0
                        {
                            break 'done;
                        }
                        (*gc).cp = ((*gc).cp).offset(2 as libc::c_int as isize);
                        if (*gc).nums_depth > (*gc).nums_maxdepth {
                            break 'done;
                        }
                        (*gc).nums[(*gc).nums_depth as usize] = 0 as libc::c_int;
                        (*gc).state = 0x2 as libc::c_int;
                    } //case 1

                    if *(*__ctype_b_loc()).offset(ch as libc::c_int as isize) as libc::c_int
                        & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int
                        == 0
                    {
                        sudo_debug_printf!(
                            SUDO_DEBUG_DEBUG | SUDO_DEBUG_LINENO,
                            b"number %d (ch %d)\0" as *const u8 as *const libc::c_char,
                            (*gc).nums[(*gc).nums_depth as usize],
                            ch as libc::c_int
                        );
                        (*gc).nums_depth += 1;
                        (*gc).state = 0 as libc::c_int;
                        continue;
                    }
                    sudo_debug_printf!(
                        SUDO_DEBUG_DEBUG | SUDO_DEBUG_LINENO,
                        b"got %d)\0" as *const u8 as *const libc::c_char,
                        ch as libc::c_int
                    );
                    if (*gc).nums[(*gc).nums_depth as usize]
                        > 2147483647 as libc::c_int / 10 as libc::c_int
                    {
                        break 'done;
                    }
                    (*gc).nums[(*gc).nums_depth as usize] *= 10 as libc::c_int;
                    (*gc).nums[(*gc).nums_depth as usize] += ch as libc::c_int - '0' as i32;
                    (*gc).state |= READCHAR as libc::c_int;
                }
                _ => {}
            }
        } //for

        break 'done;
    } // end of done;
      //if sudo_ev_add_v2(0 as *mut sudo_event_base,(*gc).ev,&mut (*gc).timeout,0 as libc::c_int != 0,) == -(1 as libc::c_int){
      //    sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char);
      //}
    debug_return!();
} //end of fn

fn xterm_get_size(mut new_rows: *mut libc::c_int, mut new_cols: *mut libc::c_int) -> bool {
    let mut evbase: *mut sudo_event_base = std::ptr::null_mut::<sudo_event_base>();
    let mut gc: getsize_closure = getsize_closure {
        nums: [0; 2],
        nums_depth: 0,
        nums_maxdepth: 0,
        state: 0,
        cp: std::ptr::null_mut::<libc::c_char>(),
        ev: std::ptr::null_mut::<sudo_event>(),
        timeout: timespec {
            tv_sec: 0,
            tv_nsec: 0,
        },
    };
    unsafe {
        let getsize_request: [libc::c_char; 20] = *::core::mem::transmute::<
            &[u8; 20],
            &[libc::c_char; 20],
        >(b"\x1B7\x1B[r\x1B[999;999H\x1B[6n\0");
        let getsize_response: [libc::c_char; 9] =
            *::core::mem::transmute::<&[u8; 9], &[libc::c_char; 9]>(b"\x1B[%d;%dR\0");
        let mut ret: bool = 0 as libc::c_int != 0;
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        if write(
            ttyfd,
            getsize_request.as_ptr() as *const libc::c_void,
            strlen(getsize_request.as_ptr()),
        ) == -(1 as libc::c_int) as libc::c_long
        {
            sudo_debug_printf!(
                SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO | SUDO_DEBUG_ERRNO,
                b"%s: error writing xterm size request\0" as *const u8 as *const libc::c_char,
                get_function_name!()
            );
            debug_return_bool!(ret);
        }

        gc.state = INITIAL as libc::c_int | READCHAR as libc::c_int;
        gc.nums_depth = 0 as libc::c_int;
        gc.nums_maxdepth = 1 as libc::c_int;
        gc.cp = getsize_response.as_ptr();
        gc.timeout.tv_sec = 10 as libc::c_int as __time_t;
        gc.timeout.tv_nsec = 0 as libc::c_int as __syscall_slong_t;
        evbase = sudo_ev_base_alloc_v1();

        if evbase.is_null() {
            sudo_fatalx!(
                b"%s: %s\0" as *const u8 as *const libc::c_char,
                get_function_name!(),
                b"unable to allocate memory\0" as *const u8 as *const libc::c_char
            );
        }
        gc.ev = sudo_ev_alloc_v1(
            ttyfd,
            SUDO_EV_READ as libc::c_int as libc::c_short,
            Some(
                getsize_cb
                    as unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> (),
            ),
            &mut gc as *mut getsize_closure as *mut libc::c_void,
        );

        if (gc.ev).is_null() {
            sudo_fatalx!(
                b"%s: %s\0" as *const u8 as *const libc::c_char,
                get_function_name!(),
                b"unable to allocate memory\0" as *const u8 as *const libc::c_char
            );
        }

        if sudo_ev_add_v2(evbase, gc.ev, &mut gc.timeout, 0 as libc::c_int != 0)
            == -(1 as libc::c_int)
        {
            sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
        }
        sudo_ev_dispatch_v1(evbase);

        if gc.state == GOTSIZE as libc::c_int {
            sudo_debug_printf!(
                SUDO_DEBUG_INFO | SUDO_DEBUG_LINENO,
                b"terminal size %d x %x\0" as *const u8 as *const libc::c_char,
                gc.nums[0 as libc::c_int as usize],
                gc.nums[1 as libc::c_int as usize]
            );
            *new_rows = gc.nums[0 as libc::c_int as usize];
            *new_cols = gc.nums[1 as libc::c_int as usize];
            ret = 1 as libc::c_int != 0;
        }
        sudo_ev_base_free_v1(evbase);
        sudo_ev_free_v1(gc.ev);
        debug_return_bool!(ret);
    } //unsaafe
}

fn xterm_set_size(mut rows: libc::c_int, mut cols: libc::c_int) -> bool {
    unsafe {
        let setsize_fmt: [libc::c_char; 11] =
            *::core::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"\x1B[8;%d;%dt\0");
        let mut len: libc::c_int = 0;
        let mut new_rows: libc::c_int = 0;
        let mut new_cols: libc::c_int = 0;
        let mut ret: bool = 0 as libc::c_int != 0;
        let mut buf: [libc::c_char; 1024] = [0; 1024];
        debug_decl!(SUDOERS_DEBUG_UTIL!());
        len = snprintf(
            buf.as_mut_ptr(),
            ::core::mem::size_of::<[libc::c_char; 1024]>() as libc::c_ulong,
            setsize_fmt.as_ptr(),
            rows,
            cols,
        );
        if len < 0 as libc::c_int
            || len as libc::c_long
                >= ::core::mem::size_of::<[libc::c_char; 1024]>() as libc::c_ulong as ssize_t
        {
            sudo_debug_printf!(
                SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                b"%s: internal error, buffer too small?\0" as *const u8 as *const libc::c_char,
                get_function_name!()
            );
            debug_return_bool!(ret);
        }

        if write(
            ttyfd,
            buf.as_mut_ptr() as *const libc::c_void,
            strlen(buf.as_mut_ptr()),
        ) == -(1 as libc::c_int) as libc::c_long
        {
            sudo_debug_printf!(
                SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO | SUDO_DEBUG_ERRNO,
                b"%s: error writing xterm resize request\0" as *const u8 as *const libc::c_char,
                get_function_name!()
            );
            debug_return_bool!(ret);
        }

        if !xterm_get_size(&mut new_rows, &mut new_cols) {
            debug_return_bool!(ret);
        }

        if rows == new_rows && cols == new_cols {
            ret = 1 as libc::c_int != 0;
        }

        debug_return_bool!(ret);
    } //unsafe
}

fn setup_terminal(mut li: *mut log_info, mut interactive: bool, mut resize: bool) {
    let mut term: *const libc::c_char = std::ptr::null::<libc::c_char>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        fflush(stdout);
        if interactive {
            ttyfd = open(
                b"/dev/tty\0" as *const u8 as *const libc::c_char,
                0o2 as libc::c_int,
            );
            while !sudo_term_raw_v1(ttyfd, 1 as libc::c_int) {
                if *__errno_location() != EINTR as libc::c_int {
                    sudo_fatal!(
                        b"unable to set tty to raw mode\0" as *const u8 as *const libc::c_char,
                    );
                }
                kill(getpid(), SIGTTOU as libc::c_int);
            }
        }
        if (*li).rows == 0 as libc::c_int && (*li).cols == 0 as libc::c_int {
            debug_return!();
        }

        if resize as libc::c_int != 0 && ttyfd != -(1 as libc::c_int) {
            term = getenv(b"TERM\0" as *const u8 as *const libc::c_char);
            if !term.is_null() && *term as libc::c_int != '\0' as i32 {
                let mut tn: *mut term_names = std::ptr::null_mut::<term_names>();
                tn = compatible_terms.as_mut_ptr();
                while !((*tn).name).is_null() {
                    if strncmp(term, (*tn).name, (*tn).len as libc::c_ulong) == 0 as libc::c_int {
                        if xterm_get_size(&mut terminal_rows, &mut terminal_cols) {
                            terminal_can_resize = 1 as libc::c_int != 0;
                        }
                        break;
                    } else {
                        tn = tn.offset(1);
                    }
                }
            }
        }
        if !terminal_can_resize {
            sudo_get_ttysize_v1(&mut terminal_rows, &mut terminal_cols);
        }
        if (*li).rows == terminal_rows && (*li).cols == terminal_cols {
            debug_return!();
        }

        if terminal_can_resize {
            if xterm_set_size((*li).rows, (*li).cols) {
                sudo_debug_printf!(
                    SUDO_DEBUG_INFO | SUDO_DEBUG_LINENO,
                    b"resized terminal to %d x %x\0" as *const u8 as *const libc::c_char,
                    (*li).rows,
                    (*li).cols
                );
                terminal_was_resized = 1 as libc::c_int != 0;
                debug_return!();
            }
            terminal_can_resize = 0 as libc::c_int != 0;
        }

        if (*li).rows > terminal_rows || (*li).cols > terminal_cols {
            fputs(
                dcgettext(
                    std::ptr::null::<libc::c_char>(),
                    b"Warning: your terminal is too small to properly replay the log.\n\0"
                        as *const u8 as *const libc::c_char,
                    5 as libc::c_int,
                ),
                stdout,
            );
            printf(
                dcgettext(
                    std::ptr::null::<libc::c_char>(),
                    b"Log geometry is %d x %d, your terminal's geometry is %d x %d.\0" as *const u8
                        as *const libc::c_char,
                    5 as libc::c_int,
                ),
                (*li).rows,
                (*li).cols,
                terminal_rows,
                terminal_cols,
            );
        }
        debug_return!();
    } //unsafe
}

fn resize_terminal(mut rows: libc::c_int, mut cols: libc::c_int) {
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        if terminal_can_resize {
            if xterm_set_size(rows, cols) {
                terminal_was_resized = 1 as libc::c_int != 0;
            } else {
                terminal_can_resize = 0 as libc::c_int != 0;
            }
        }
        debug_return!();
    } //unsafe
}

fn restore_terminal_size() {
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());
        if terminal_was_resized {
            putchar('\r' as i32);
            fputs(
                sudo_warn_gettext_v1(
                    std::ptr::null::<libc::c_char>(),
                    b"Replay finished, press any key to restore the terminal.\0" as *const u8
                        as *const libc::c_char,
                ),
                stdout,
            );
            fflush(stdout);
            getchar();
            xterm_set_size(terminal_rows, terminal_cols);
            putchar('\r' as i32);
            putchar('\n' as i32);
        }
        debug_return!();
    } //unsafe
}
fn read_timing_record(mut closure: *mut replay_closure) -> libc::c_int {
    let mut timeout: timespec = timespec {
        tv_sec: 0,
        tv_nsec: 0,
    };
    let mut buf: [libc::c_char; LINE_MAX as usize] = [0; LINE_MAX as usize];
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        if (io_log_gets(
            io_log_files[5 as libc::c_int as usize].fd,
            buf.as_mut_ptr(),
            ::core::mem::size_of::<[libc::c_char; 2048]>() as libc::c_ulong,
        ))
        .is_null()
        {
            debug_return_int!(
                if io_log_eof(io_log_files[5 as libc::c_int as usize].fd) != 0 {
                    1 as libc::c_int
                } else {
                    -(1 as libc::c_int)
                }
            );
        }

        buf[strcspn(
            buf.as_mut_ptr(),
            b"\n\0" as *const u8 as *const libc::c_char,
        ) as usize] = '\0' as i32 as libc::c_char;

        if !parse_timing(buf.as_mut_ptr(), &mut timeout, &mut (*closure).timing) {
            sudo_fatalx!(
                b"invalid timing file line: %s\0" as *const u8 as *const libc::c_char,
                buf
            );
        }
        if (*closure).timing.event != IO_EVENT_WINSIZE as libc::c_int
            && (*closure).timing.event != IO_EVENT_SUSPEND as libc::c_int
        {
            (*closure).iobuf.len = 0 as libc::c_int as libc::c_uint;
            (*closure).iobuf.off = 0 as libc::c_int as libc::c_uint;
            (*closure).iobuf.lastc = '\0' as i32;
            (*closure).iobuf.toread = (*closure).timing.u.nbytes as libc::c_uint;
        }
        adjust_delay(&mut timeout, (*closure).timing.max_delay, speed_factor);
        if sudo_ev_add_v2(
            (*closure).evbase,
            (*closure).delay_ev,
            &mut timeout,
            0 as libc::c_int != 0,
        ) == -(1 as libc::c_int)
        {
            sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
        }
        debug_return_int!(0);
    } //unsafe
}

fn next_timing_record(mut closure: *mut replay_closure) {
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        'again: loop {
            match read_timing_record(closure) {
                0 => {
                    if (*closure).timing.event == IO_EVENT_SUSPEND as libc::c_int
                        && (*closure).timing.u.signo == SIGCONT as libc::c_int
                        && !(*closure).suspend_wait
                    {
                        continue;
                    }
                }
                1 => {
                    sudo_ev_loopexit_v1((*closure).evbase);
                }
                _ => {
                    sudo_ev_loopbreak_v1((*closure).evbase);
                }
            }
            break 'again;
        }
        debug_return!();
    } //unsafe
}

fn fill_iobuf(mut closure: *mut replay_closure) -> bool {
    unsafe {
        let space: size_t = (::core::mem::size_of::<[libc::c_char; 65536]>() as libc::c_ulong)
            .wrapping_sub((*closure).iobuf.len as libc::c_ulong);
        let mut timing: *const timing_closure = &mut (*closure).timing;
        debug_decl!(SUDOERS_DEBUG_UTIL!());
        if (*closure).iobuf.toread != 0 as libc::c_int as libc::c_uint
            && space != 0 as libc::c_int as libc::c_ulong
        {
            let len: size_t = if ((*closure).iobuf.toread as libc::c_ulong) < space {
                (*closure).iobuf.toread as libc::c_ulong
            } else {
                space
            };
            let mut nread: ssize_t = io_log_read(
                (*timing).fd,
                ((*closure).iobuf.buf)
                    .as_mut_ptr()
                    .offset((*closure).iobuf.off as isize),
                len,
            );
            if nread <= 0 as libc::c_int as libc::c_long {
                if nread == 0 as libc::c_int as libc::c_long {
                    sudo_debug_printf!(
                        SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                        b"%s: premature EOF, expected %u bytes\0" as *const u8
                            as *const libc::c_char,
                        io_log_files[(*timing).event as usize].suffix,
                        (*closure).iobuf.toread
                    );
                } else {
                    sudo_debug_printf!(
                        SUDO_DEBUG_ERROR | SUDO_DEBUG_ERRNO | SUDO_DEBUG_LINENO,
                        b"%s: read error\0" as *const u8 as *const libc::c_char,
                        io_log_files[(*timing).event as usize].suffix
                    );
                }
                sudo_warnx!(
                    b"unable to read %s\0" as *const u8 as *const libc::c_char,
                    io_log_files[(*timing).event as usize].suffix,
                );
                debug_return_bool!(false);
            }
            (*closure).iobuf.toread =
                ((*closure).iobuf.toread as libc::c_long - nread) as libc::c_uint;
            (*closure).iobuf.len = ((*closure).iobuf.len as libc::c_long + nread) as libc::c_uint;
        }
        debug_return_bool!(true);
    } //unsafe
}

unsafe extern "C" fn delay_cb(
    mut fd: libc::c_int,
    mut what: libc::c_int,
    mut v: *mut libc::c_void,
) {
    let mut closure: *mut replay_closure = v as *mut replay_closure;
    let mut timing: *mut timing_closure = &mut (*closure).timing;
    debug_decl!(SUDOERS_DEBUG_UTIL!());

    match (*timing).event {
        IO_EVENT_WINSIZE => {
            resize_terminal((*timing).u.winsize.rows, (*timing).u.winsize.cols);
        }
        IO_EVENT_STDIN => {
            if io_log_files[0 as libc::c_int as usize].enabled {
                (*timing).fd = io_log_files[0 as libc::c_int as usize].fd;
            }
        }
        IO_EVENT_STDOUT => {
            if io_log_files[1 as libc::c_int as usize].enabled {
                (*timing).fd = io_log_files[1 as libc::c_int as usize].fd;
            }
        }
        IO_EVENT_STDERR => {
            if io_log_files[2 as libc::c_int as usize].enabled {
                (*timing).fd = io_log_files[2 as libc::c_int as usize].fd;
            }
        }
        IO_EVENT_TTYIN => {
            if io_log_files[3 as libc::c_int as usize].enabled {
                (*timing).fd = io_log_files[3 as libc::c_int as usize].fd;
            }
        }
        IO_EVENT_TTYOUT => {
            if io_log_files[4 as libc::c_int as usize].enabled {
                (*timing).fd = io_log_files[4 as libc::c_int as usize].fd;
            }
        }
        _ => {}
    }
    if !((*timing).fd.v).is_null() {
        if sudo_ev_add_v2(
            (*closure).evbase,
            (*closure).output_ev,
            std::ptr::null_mut::<timespec>(),
            0 as libc::c_int != 0,
        ) == -(1 as libc::c_int)
        {
            sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
        }
    } else {
        next_timing_record(closure);
    }
    debug_return!();
}

unsafe extern "C" fn replay_closure_free(mut closure: *mut replay_closure) {
    sudo_ev_free_v1((*closure).delay_ev);
    sudo_ev_free_v1((*closure).keyboard_ev);
    sudo_ev_free_v1((*closure).output_ev);
    sudo_ev_free_v1((*closure).sighup_ev);
    sudo_ev_free_v1((*closure).sigint_ev);
    sudo_ev_free_v1((*closure).sigquit_ev);
    sudo_ev_free_v1((*closure).sigterm_ev);
    sudo_ev_free_v1((*closure).sigtstp_ev);
    sudo_ev_base_free_v1((*closure).evbase);
    free(closure as *mut libc::c_void);
}

unsafe extern "C" fn signal_cb(
    mut signo: libc::c_int,
    mut what: libc::c_int,
    mut v: *mut libc::c_void,
) {
    let mut closure: *mut replay_closure = v as *mut replay_closure;
    debug_decl!(SUDOERS_DEBUG_UTIL!());

    match signo {
        SIGHUP | SIGINT | SIGQUIT | SIGTERM => {
            replay_closure_free(closure);
            sudoreplay_cleanup();
            kill(getpid(), signo);
        }
        _ => {}
    }
    debug_return!();
}

fn replay_closure_alloc(
    mut max_delay: *mut timespec,
    mut decimal: *const libc::c_char,
    mut interactive: bool,
    mut suspend_wait: bool,
) -> *mut replay_closure {
    //let mut current_block: u64;
    let mut closure: *mut replay_closure = std::ptr::null_mut::<replay_closure>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        closure = calloc(
            1 as libc::c_int as libc::c_ulong,
            ::core::mem::size_of::<replay_closure>() as libc::c_ulong,
        ) as *mut replay_closure;
        if closure.is_null() {
            debug_return_ptr!(std::ptr::null_mut::<replay_closure>());
        }

        (*closure).interactive = interactive;
        (*closure).suspend_wait = suspend_wait;
        (*closure).timing.max_delay = max_delay;
        (*closure).timing.decimal = decimal;
        (*closure).evbase = sudo_ev_base_alloc_v1();

        'bad: loop {
            if ((*closure).evbase).is_null() {
                break 'bad;
            }

            (*closure).delay_ev = sudo_ev_alloc_v1(
                -(1 as libc::c_int),
                SUDO_EV_TIMEOUT as libc::c_int as libc::c_short,
                Some(
                    delay_cb
                        as unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> (),
                ),
                closure as *mut libc::c_void,
            );
            if ((*closure).delay_ev).is_null() {
                break 'bad;
            }

            if interactive {
                (*closure).keyboard_ev = sudo_ev_alloc_v1(
                    ttyfd,
                    (0x2 as libc::c_int | 0x8 as libc::c_int) as libc::c_short,
                    Some(
                        read_keyboard
                            as unsafe extern "C" fn(
                                libc::c_int,
                                libc::c_int,
                                *mut libc::c_void,
                            ) -> (),
                    ),
                    closure as *mut libc::c_void,
                );
                if ((*closure).keyboard_ev).is_null() {
                    break 'bad;
                }
                if sudo_ev_add_v2(
                    (*closure).evbase,
                    (*closure).keyboard_ev,
                    std::ptr::null_mut::<timespec>(),
                    0 as libc::c_int != 0,
                ) == -(1 as libc::c_int)
                {
                    sudo_fatal!(
                        b"unable to add event to queue\0" as *const u8 as *const libc::c_char,
                    );
                }
            }

            (*closure).output_ev = sudo_ev_alloc_v1(
                if interactive as libc::c_int != 0 {
                    ttyfd
                } else {
                    1 as libc::c_int
                },
                0x4 as libc::c_int as libc::c_short,
                Some(
                    write_output
                        as unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> (),
                ),
                closure as *mut libc::c_void,
            );

            if ((*closure).output_ev).is_null() {
                break 'bad;
            }

            (*closure).sighup_ev = sudo_ev_alloc_v1(
                SIGHUP as libc::c_int,
                SUDO_EV_SIGNAL as libc::c_int as libc::c_short,
                Some(
                    signal_cb
                        as unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> (),
                ),
                closure as *mut libc::c_void,
            );

            if ((*closure).sighup_ev).is_null() {
                break 'bad;
            }

            if sudo_ev_add_v2(
                (*closure).evbase,
                (*closure).sighup_ev,
                std::ptr::null_mut::<timespec>(),
                0 as libc::c_int != 0,
            ) == -(1 as libc::c_int)
            {
                sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
            }

            (*closure).sigint_ev = sudo_ev_alloc_v1(
                SIGINT as libc::c_int,
                SUDO_EV_SIGNAL as libc::c_int as libc::c_short,
                Some(
                    signal_cb
                        as unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> (),
                ),
                closure as *mut libc::c_void,
            );

            if ((*closure).sigint_ev).is_null() {
                break 'bad;
            }

            if sudo_ev_add_v2(
                (*closure).evbase,
                (*closure).sigint_ev,
                std::ptr::null_mut::<timespec>(),
                0 as libc::c_int != 0,
            ) == -(1 as libc::c_int)
            {
                sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
            }

            (*closure).sigquit_ev = sudo_ev_alloc_v1(
                SIGQUIT as libc::c_int,
                SUDO_EV_SIGNAL as libc::c_int as libc::c_short,
                Some(
                    signal_cb
                        as unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> (),
                ),
                closure as *mut libc::c_void,
            );

            if ((*closure).sigquit_ev).is_null() {
                break 'bad;
            }

            if sudo_ev_add_v2(
                (*closure).evbase,
                (*closure).sigquit_ev,
                std::ptr::null_mut::<timespec>(),
                0 as libc::c_int != 0,
            ) == -(1 as libc::c_int)
            {
                sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
            }

            (*closure).sigterm_ev = sudo_ev_alloc_v1(
                SIGTERM as libc::c_int,
                SUDO_EV_SIGNAL as libc::c_int as libc::c_short,
                Some(
                    signal_cb
                        as unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> (),
                ),
                closure as *mut libc::c_void,
            );

            if ((*closure).sigterm_ev).is_null() {
                break 'bad;
            }

            if sudo_ev_add_v2(
                (*closure).evbase,
                (*closure).sigterm_ev,
                std::ptr::null_mut::<timespec>(),
                0 as libc::c_int != 0,
            ) == -(1 as libc::c_int)
            {
                sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
            }

            (*closure).sigtstp_ev = sudo_ev_alloc_v1(
                SIGTSTP as libc::c_int,
                SUDO_EV_SIGNAL as libc::c_int as libc::c_short,
                Some(
                    signal_cb
                        as unsafe extern "C" fn(libc::c_int, libc::c_int, *mut libc::c_void) -> (),
                ),
                closure as *mut libc::c_void,
            );

            if ((*closure).sigtstp_ev).is_null() {
                break 'bad;
            }

            if sudo_ev_add_v2(
                (*closure).evbase,
                (*closure).sigtstp_ev,
                std::ptr::null_mut::<timespec>(),
                0 as libc::c_int != 0,
            ) == -(1 as libc::c_int)
            {
                sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
            }

            debug_return_ptr!(closure);
            //own
            break 'bad;
        }
        replay_closure_free(closure);
        debug_return_ptr!(std::ptr::null_mut::<replay_closure>());
    } //unsafe
}

fn replay_session(
    mut max_delay: *mut timespec,
    mut decimal: *const libc::c_char,
    mut interactive: bool,
    mut suspend_wait: bool,
) -> libc::c_int {
    let mut closure: *mut replay_closure = std::ptr::null_mut::<replay_closure>();
    let mut ret: libc::c_int = 0 as libc::c_int;
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        closure = replay_closure_alloc(max_delay, decimal, interactive, suspend_wait);

        if read_timing_record(closure) != 0 as libc::c_int {
            ret = 1 as libc::c_int;
            replay_closure_free(closure);
            debug_return_int!(ret);
        }
        sudo_ev_dispatch_v1((*closure).evbase);
        if sudo_ev_got_break_v1((*closure).evbase) {
            ret = 1 as libc::c_int;
        }
        replay_closure_free(closure);
        debug_return_int!(ret);
    } //unsafe
}

fn open_io_fd(
    mut path: *mut libc::c_char,
    mut len: libc::c_int,
    mut iol: *mut io_log_file,
) -> libc::c_int {
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        if !(*iol).enabled {
            debug_return_int!(0);
        }

        *path.offset(len as isize) = '\0' as i32 as libc::c_char;

        sudo_strlcat(path, (*iol).suffix, PATH_MAX as libc::c_int as size_t);
        (*iol).fd.g = gzopen(path, b"r\0" as *const u8 as *const libc::c_char);

        if ((*iol).fd.v).is_null() {
            (*iol).enabled = 0 as libc::c_int != 0;
            debug_return_int!(-1);
        }
        debug_return_int!(0);
    } //unsafe
}

unsafe extern "C" fn write_output(
    mut fd: libc::c_int,
    mut what: libc::c_int,
    mut v: *mut libc::c_void,
) {
    let mut closure: *mut replay_closure = v as *mut replay_closure;
    let mut timing: *const timing_closure = &mut (*closure).timing;
    let mut iobuf: *mut io_buffer = &mut (*closure).iobuf;
    let mut iovcnt: libc::c_uint = 1 as libc::c_int as libc::c_uint;
    let mut iov: [iovec; 2] = [iovec {
        iov_base: std::ptr::null_mut::<libc::c_void>(),
        iov_len: 0,
    }; 2];
    let mut added_cr: bool = 0 as libc::c_int != 0;
    let mut nbytes: size_t = 0;
    let mut nwritten: size_t = 0;
    debug_decl!(SUDOERS_DEBUG_UTIL!());
    if !fill_iobuf(closure) {
        sudo_ev_loopbreak_v1((*closure).evbase);
        debug_return!();
    }

    nbytes = ((*iobuf).len).wrapping_sub((*iobuf).off) as size_t;
    iov[0 as libc::c_int as usize].iov_base =
        ((*iobuf).buf).as_mut_ptr().offset((*iobuf).off as isize) as *mut libc::c_void;
    iov[0 as libc::c_int as usize].iov_len = nbytes;
    if (*closure).interactive as libc::c_int != 0
        && ((*timing).event == IO_EVENT_STDOUT as libc::c_int
            || (*timing).event == IO_EVENT_STDERR as libc::c_int)
    {
        let mut nl: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
        nl = memchr(
            iov[0 as libc::c_int as usize].iov_base,
            '\n' as i32,
            iov[0 as libc::c_int as usize].iov_len,
        ) as *mut libc::c_char;
        if !nl.is_null() {
            let mut len: size_t = nl
                .offset_from(iov[0 as libc::c_int as usize].iov_base as *mut libc::c_char)
                as libc::c_long as size_t;
            if nl == iov[0 as libc::c_int as usize].iov_base as *mut libc::c_char
                && (*iobuf).lastc != '\r' as i32
                || nl != iov[0 as libc::c_int as usize].iov_base as *mut libc::c_char
                    && *nl.offset(-(1 as libc::c_int) as isize) as libc::c_int != '\r' as i32
            {
                iov[0 as libc::c_int as usize].iov_len = len;
                iov[1 as libc::c_int as usize].iov_base =
                    b"\r\n\0" as *const u8 as *const libc::c_char as *mut libc::c_void;
                iov[1 as libc::c_int as usize].iov_len = 2 as libc::c_int as size_t;
                iovcnt = 2 as libc::c_int as libc::c_uint;
                nbytes = (iov[0 as libc::c_int as usize].iov_len)
                    .wrapping_add(iov[1 as libc::c_int as usize].iov_len);
                added_cr = 1 as libc::c_int != 0;
            }
        }
    }

    nwritten = writev(fd, iov.as_mut_ptr(), iovcnt as libc::c_int) as size_t;
    match nwritten as ssize_t {
        -1 => {
            if *__errno_location() != EINTR as libc::c_int
                && *__errno_location() != EAGAIN as libc::c_int
            {
                sudo_fatal!(
                    b"unable to write to %s\0" as *const u8 as *const libc::c_char,
                    b"stdout\0" as *const u8 as *const libc::c_char
                );
            }
        }
        0 => {}
        _ => {
            if added_cr as libc::c_int != 0
                && nwritten >= nbytes.wrapping_sub(1 as libc::c_int as libc::c_ulong)
            {
                (*iobuf).lastc = if nwritten == nbytes {
                    '\n' as i32
                } else {
                    '\r' as i32
                };
            } else {
                (*iobuf).lastc = *(iov[0 as libc::c_int as usize].iov_base as *mut libc::c_char)
                    .offset(nwritten as isize) as libc::c_int;
            }
            if added_cr {
                nwritten = nwritten.wrapping_sub(1);
            }
            (*iobuf).off = ((*iobuf).off as libc::c_ulong).wrapping_add(nwritten) as libc::c_uint
                as libc::c_uint;
        }
    }
    if (*iobuf).off == (*iobuf).len {
        match read_timing_record(closure) {
            0 => {}
            1 => {
                sudo_ev_loopexit_v1((*closure).evbase);
            }
            _ => {
                sudo_ev_loopbreak_v1((*closure).evbase);
            }
        }
    } else if sudo_ev_add_v2(
        std::ptr::null_mut::<sudo_event_base>(),
        (*closure).output_ev,
        std::ptr::null_mut::<timespec>(),
        0 as libc::c_int != 0,
    ) == -(1 as libc::c_int)
    {
        sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
    }

    /*} else {
        if sudo_ev_add_v2(
            std::ptr::null_mut::<sudo_event_base>(),
            (*closure).output_ev,
            std::ptr::null_mut::<timespec>(),
            0 as libc::c_int != 0,
        ) == -(1 as libc::c_int)
        {
            sudo_fatal!(b"unable to add event to queue\0" as *const u8 as *const libc::c_char,);
        }
    }*/
    debug_return!();
}

fn parse_expr(
    mut head: *mut search_node_list,
    mut argv: *mut *mut libc::c_char,
    mut sub_expr: bool,
) -> libc::c_int {
    let mut current_block: u64;
    let mut or: bool = 0 as libc::c_int != 0;
    let mut not: bool = 0 as libc::c_int != 0;
    let mut sn: *mut search_node = std::ptr::null_mut::<search_node>();
    let mut type_0: libc::c_char = 0;
    let mut av: *mut *mut libc::c_char = std::ptr::null_mut::<*mut libc::c_char>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        av = argv;
        while !(*av).is_null() {
            match *(*av.offset(0 as libc::c_int as isize)).offset(0 as libc::c_int as isize) as u8
                as char
            {
                'a' => {
                    //a 97
                    if strncmp(
                        *av,
                        b"and\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) != 0 as libc::c_int
                    {
                        //bad;
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    av = av.offset(1);
                    continue;
                }
                'o' => {
                    // o 111
                    if strncmp(
                        *av,
                        b"or\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) != 0 as libc::c_int
                    {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    or = 1 as libc::c_int != 0;
                    av = av.offset(1);
                    continue;
                }
                '!' => {
                    // ! 33
                    if *(*av.offset(0 as libc::c_int as isize)).offset(1 as libc::c_int as isize)
                        as libc::c_int
                        != '\0' as i32
                    {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    not = 1 as libc::c_int != 0;
                    av = av.offset(1);
                    continue;
                }
                'c' => {
                    //c 99
                    if *(*av.offset(0 as libc::c_int as isize)).offset(1 as libc::c_int as isize)
                        as libc::c_int
                        == '\0' as i32
                    {
                        sudo_fatalx!(
                            b"ambiguous expression \"%s\"\0" as *const u8 as *const libc::c_char,
                            *av
                        );
                    }
                    if strncmp(
                        *av,
                        b"cwd\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) == 0 as libc::c_int
                    {
                        type_0 = ST_CWD as libc::c_int as libc::c_char;
                    } else if strncmp(
                        *av,
                        b"command\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) == 0 as libc::c_int
                    {
                        type_0 = ST_PATTERN as libc::c_int as libc::c_char;
                    } else {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                }
                'f' => {
                    //f 102
                    if strncmp(
                        *av,
                        b"fromdate\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) != 0 as libc::c_int
                    {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    type_0 = ST_FROMDATE as libc::c_int as libc::c_char;
                }
                'g' => {
                    //g 103
                    if strncmp(
                        *av,
                        b"group\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) != 0 as libc::c_int
                    {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    type_0 = ST_RUNASGROUP as libc::c_int as libc::c_char;
                }
                'r' => {
                    //r 114
                    if strncmp(
                        *av,
                        b"runas\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) != 0 as libc::c_int
                    {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    type_0 = ST_RUNASUSER as libc::c_int as libc::c_char;
                }
                't' => {
                    //t 116
                    if *(*av.offset(0 as libc::c_int as isize)).offset(1 as libc::c_int as isize)
                        as libc::c_int
                        == '\0' as i32
                    {
                        sudo_fatalx!(
                            b"ambiguous expression \"%s\"\0" as *const u8 as *const libc::c_char,
                            *av
                        );
                    }
                    if strncmp(
                        *av,
                        b"todate\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) == 0 as libc::c_int
                    {
                        type_0 = ST_TODATE as libc::c_int as libc::c_char;
                    } else if strncmp(
                        *av,
                        b"tty\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) == 0 as libc::c_int
                    {
                        type_0 = ST_TTY as libc::c_int as libc::c_char;
                    } else {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                }
                'u' => {
                    //u 117
                    if strncmp(
                        *av,
                        b"user\0" as *const u8 as *const libc::c_char,
                        strlen(*av),
                    ) != 0 as libc::c_int
                    {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    type_0 = ST_USER as libc::c_int as libc::c_char;
                }
                '(' => {
                    //( 40
                    if *(*av.offset(0 as libc::c_int as isize)).offset(1 as libc::c_int as isize)
                        as libc::c_int
                        != '\0' as i32
                    {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    type_0 = ST_EXPR as libc::c_int as libc::c_char;
                }
                ')' => {
                    //) 41
                    if *(*av.offset(0 as libc::c_int as isize)).offset(1 as libc::c_int as isize)
                        as libc::c_int
                        != '\0' as i32
                    {
                        sudo_fatalx!(
                            b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    if !sub_expr {
                        sudo_fatalx!(
                            b"unmatched ')' in expression\0" as *const u8 as *const libc::c_char,
                        );
                    }
                    debug_return_int!(av.offset_from(argv) as libc::c_int + 1 as libc::c_int);
                }
                _ => {
                    sudo_fatalx!(
                        b"unknown search term \"%s\"\0" as *const u8 as *const libc::c_char,
                    );
                }
            }

            sn = calloc(
                1 as libc::c_int as libc::c_ulong,
                ::core::mem::size_of::<search_node>() as libc::c_ulong,
            ) as *mut search_node;
            if sn.is_null() {
                sudo_fatalx!(
                    b"%s: %s\0" as *const u8 as *const libc::c_char,
                    get_function_name!(),
                    b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                );
            }
            (*sn).type_0 = type_0;
            (*sn).or = or;
            (*sn).negated = not;
            if type_0 as libc::c_int == 1 as libc::c_int {
                (*sn).u.expr.stqh_first = std::ptr::null_mut::<search_node>();
                (*sn).u.expr.stqh_last = &mut (*sn).u.expr.stqh_first;
                av = av.offset(parse_expr(
                    &mut (*sn).u.expr,
                    av.offset(1 as libc::c_int as isize),
                    1 as libc::c_int != 0,
                ) as isize);
            } else {
                av = av.offset(1);
                if (*av).is_null() {
                    sudo_fatalx!(
                        b"%s requires an argument\0" as *const u8 as *const libc::c_char,
                        *av.offset(-(1 as libc::c_int) as isize)
                    );
                }
                if type_0 as libc::c_int == ST_PATTERN as libc::c_int {
                    if regcomp(
                        &mut (*sn).u.cmdre,
                        *av,
                        1 as libc::c_int | (1 as libc::c_int) << 3 as libc::c_int,
                    ) != 0 as libc::c_int
                    {
                        sudo_fatalx!(
                            b"invalid reqular expression: %s\0" as *const u8 as *const libc::c_char,
                            *av
                        );
                    }
                } else if type_0 as libc::c_int == ST_TODATE as libc::c_int
                    || type_0 as libc::c_int == ST_FROMDATE as libc::c_int
                {
                    (*sn).u.tstamp = get_date(*av);
                    if (*sn).u.tstamp == -(1 as libc::c_int) as libc::c_long {
                        sudo_fatalx!(
                            b"could not parse date \"%s\"\0" as *const u8 as *const libc::c_char,
                            *av
                        );
                    }
                } else {
                    (*sn).u.ptr = *av as *mut libc::c_void;
                }
            }
            /////
            or = 0 as libc::c_int != 0;
            not = or;
            (*sn).entries.stqe_next = std::ptr::null_mut::<search_node>();
            *(*head).stqh_last = sn;
            (*head).stqh_last = &mut (*sn).entries.stqe_next;

            av = av.offset(1);
        } //while as for
          ////////////////////////
        if sub_expr {
            sudo_fatalx!(b"unmatched '(' in expression\0" as *const u8 as *const libc::c_char,);
        }
        if or {
            sudo_fatalx!(b"illegal trailing \"or\"\0" as *const u8 as *const libc::c_char,);
        }
        if not {
            sudo_fatalx!(b"illegal trailing \"!\"\0" as *const u8 as *const libc::c_char,);
        }
        debug_return_int!(av.offset_from(argv) as libc::c_long as libc::c_int);
    } //unsafe
}

fn match_expr(
    mut head: *mut search_node_list,
    mut log: *mut log_info,
    mut last_match: bool,
) -> bool {
    let mut sn: *mut search_node = std::ptr::null_mut::<search_node>();
    let mut res: bool = 0 as libc::c_int != 0;
    let mut matched: bool = last_match;
    let mut rc: libc::c_int = 0;
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        sn = (*head).stqh_first;
        while !sn.is_null() {
            match (*sn).type_0 as libc::c_int {
                ST_EXPR => {
                    res = match_expr(&mut (*sn).u.expr, log, matched);
                }
                ST_CWD => {
                    res = strcmp((*sn).u.cwd, (*log).cwd) == 0 as libc::c_int;
                }
                ST_TTY => {
                    res = strcmp((*sn).u.tty, (*log).tty) == 0 as libc::c_int;
                }
                ST_RUNASGROUP => {
                    if !((*log).runas_group).is_null() {
                        res = strcmp((*sn).u.runas_group, (*log).runas_group) == 0 as libc::c_int;
                    }
                }
                ST_RUNASUSER => {
                    res = strcmp((*sn).u.runas_user, (*log).runas_user) == 0 as libc::c_int;
                }
                ST_USER => {
                    res = strcmp((*sn).u.user, (*log).user) == 0 as libc::c_int;
                }
                ST_PATTERN => {
                    rc = regexec(
                        &(*sn).u.cmdre,
                        (*log).cmd,
                        0 as libc::c_int as size_t,
                        std::ptr::null_mut::<regmatch_t>(),
                        0 as libc::c_int,
                    );
                    if rc != 0 && rc != _REG_NOMATCH as libc::c_int {
                        let mut buf: [libc::c_char; 8192] = [0; 8192];
                        regerror(
                            rc,
                            &(*sn).u.cmdre,
                            buf.as_mut_ptr(),
                            ::core::mem::size_of::<[libc::c_char; 8192]>() as libc::c_ulong,
                        );
                        sudo_fatalx!(b"%s\0" as *const u8 as *const libc::c_char, buf,);
                    }
                    res = if rc == _REG_NOMATCH as libc::c_int {
                        0 as libc::c_int
                    } else {
                        1 as libc::c_int
                    } != 0;
                }
                ST_FROMDATE => {
                    res = (*log).tstamp >= (*sn).u.tstamp;
                }
                ST_TODATE => {
                    res = (*log).tstamp <= (*sn).u.tstamp;
                }
                _ => {
                    sudo_fatalx!(
                        b"unknown search type %d\0" as *const u8 as *const libc::c_char,
                        (*sn).type_0 as libc::c_int,
                    );
                }
            }
            if (*sn).negated {
                res = !res;
            }
            matched = if (*sn).or as libc::c_int != 0 {
                (res as libc::c_int != 0 || last_match as libc::c_int != 0) as libc::c_int
            } else {
                (res as libc::c_int != 0 && last_match as libc::c_int != 0) as libc::c_int
            } != 0;
            last_match = matched;
            sn = (*sn).entries.stqe_next;
        }
        debug_return_bool!(matched);
    } //unsafe
}

fn list_session(
    mut logfile: *mut libc::c_char,
    mut re: *mut regex_t,
    mut user: *const libc::c_char,
    mut tty: *const libc::c_char,
) -> libc::c_int {
    let mut idbuf: [libc::c_char; 7] = [0; 7];
    let mut idstr: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut cp: *mut libc::c_char = std::ptr::null_mut::<libc::c_char>();
    let mut timestr: *const libc::c_char = std::ptr::null::<libc::c_char>();
    let mut li: *mut log_info = std::ptr::null_mut::<log_info>();
    let mut ret: libc::c_int = -(1 as libc::c_int);
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        li = parse_logfile(logfile);
        if li.is_null() {
            free_log_info(li);
            debug_return_int!(ret);
        }

        if !(search_expr.stqh_first).is_null()
            && !match_expr(&mut search_expr, li, 1 as libc::c_int != 0)
        {
            free_log_info(li);
            debug_return_int!(ret);
        }

        cp = logfile
            .offset(strlen(session_dir) as isize)
            .offset(1 as libc::c_int as isize);
        if IS_IDLOG!(cp) {
            idbuf[0 as libc::c_int as usize] = *cp.offset(0 as libc::c_int as isize);
            idbuf[1 as libc::c_int as usize] = *cp.offset(1 as libc::c_int as isize);
            idbuf[2 as libc::c_int as usize] = *cp.offset(3 as libc::c_int as isize);
            idbuf[3 as libc::c_int as usize] = *cp.offset(4 as libc::c_int as isize);
            idbuf[4 as libc::c_int as usize] = *cp.offset(6 as libc::c_int as isize);
            idbuf[5 as libc::c_int as usize] = *cp.offset(7 as libc::c_int as isize);
            idbuf[6 as libc::c_int as usize] = '\0' as i32 as libc::c_char;
            idstr = idbuf.as_mut_ptr();
        } else {
            *cp.offset((strlen(cp)).wrapping_sub(4 as libc::c_int as libc::c_ulong) as isize) =
                '\0' as i32 as libc::c_char;
            idstr = cp;
        }

        timestr = get_timestr((*li).tstamp, 1 as libc::c_int);
        printf(
            b"%s : %s : TTY=%s ; CWD=%s ; USER=%s ; \0" as *const u8 as *const libc::c_char,
            if !timestr.is_null() {
                timestr
            } else {
                b"invalid date\0" as *const u8 as *const libc::c_char
            },
            (*li).user,
            (*li).tty,
            (*li).cwd,
            (*li).runas_user,
        );
        if !((*li).runas_group).is_null() {
            printf(
                b"GROUP=%s ; \0" as *const u8 as *const libc::c_char,
                (*li).runas_group,
            );
        }
        printf(
            b"TSID=%s ; COMMAND=%s\n\0" as *const u8 as *const libc::c_char,
            idstr,
            (*li).cmd,
        );
        ret = 0 as libc::c_int;
        free_log_info(li);
        debug_return_int!(ret);
    } //unsafe
}

unsafe extern "C" fn session_compare(
    mut v1: *const libc::c_void,
    mut v2: *const libc::c_void,
) -> libc::c_int {
    let mut s1: *const libc::c_char = *(v1 as *mut *const libc::c_char);
    let mut s2: *const libc::c_char = *(v2 as *mut *const libc::c_char);
    strcmp(s1, s2)
}

fn find_sessions(
    mut dir: *const libc::c_char,
    mut re: *mut regex_t,
    mut user: *const libc::c_char,
    mut tty: *const libc::c_char,
) -> libc::c_int {
    let mut d: *mut DIR = std::ptr::null_mut::<DIR>();
    let mut dp: *mut dirent = std::ptr::null_mut::<dirent>();
    let mut sb: stat = sb_all_arch;
    let mut sdlen: size_t = 0;
    let mut sessions_len: size_t = 0 as libc::c_int as size_t;
    let mut sessions_size: size_t = 0 as libc::c_int as size_t;
    let mut i: libc::c_uint = 0;
    let mut len: libc::c_int = 0;
    let mut pathbuf: [libc::c_char; 4096] = [0; 4096];
    let mut sessions: *mut *mut libc::c_char = std::ptr::null_mut::<*mut libc::c_char>();
    let mut checked_type: bool = 1 as libc::c_int != 0;
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        d = opendir(dir);
        if d.is_null() {
            sudo_fatal!(
                b"unable to open %s\0" as *const u8 as *const libc::c_char,
                dir
            );
        }

        sdlen = sudo_strlcpy(
            pathbuf.as_mut_ptr(),
            dir,
            ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong,
        );
        if sdlen.wrapping_add(1 as libc::c_int as libc::c_ulong)
            >= ::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong
        {
            *__errno_location() = ENAMETOOLONG as libc::c_int;
            sudo_fatal!(b"%s/\0" as *const u8 as *const libc::c_char, dir);
        }
        let fresh0 = sdlen;
        sdlen = sdlen.wrapping_add(1);
        pathbuf[fresh0 as usize] = '/' as i32 as libc::c_char;
        pathbuf[sdlen as usize] = '\0' as i32 as libc::c_char;
        loop {
            dp = readdir(d);
            if dp.is_null() {
                break;
            }
            if (*dp).d_name[0 as libc::c_int as usize] as libc::c_int == '.' as i32
                && ((*dp).d_name[1 as libc::c_int as usize] as libc::c_int == '\0' as i32
                    || (*dp).d_name[1 as libc::c_int as usize] as libc::c_int == '.' as i32
                        && (*dp).d_name[2 as libc::c_int as usize] as libc::c_int == '\0' as i32)
            {
                continue;
            }
            /*if checked_type {
                if (*dp).d_type as libc::c_int != DT_DIR as libc::c_int {
                    if (*dp).d_type as libc::c_int != DT_UNKNOWN as libc::c_int {
                        continue;
                    }
                    checked_type = 0 as libc::c_int != 0;
                }
            }*/
            if checked_type && (*dp).d_type as libc::c_int != DT_DIR as libc::c_int {
                if (*dp).d_type as libc::c_int != DT_UNKNOWN as libc::c_int {
                    continue;
                }
                checked_type = 0 as libc::c_int != 0;
            }

            if sessions_len.wrapping_add(1 as libc::c_int as libc::c_ulong) > sessions_size {
                if sessions_size == 0 as libc::c_int as libc::c_ulong {
                    sessions_size =
                        (36 as libc::c_int * 36 as libc::c_int / 2 as libc::c_int) as size_t;
                }
                sessions = reallocarray(
                    sessions as *mut libc::c_void,
                    sessions_size,
                    (2 as libc::c_int as libc::c_ulong)
                        .wrapping_mul(::core::mem::size_of::<*mut libc::c_char>() as libc::c_ulong),
                ) as *mut *mut libc::c_char;

                if sessions.is_null() {
                    sudo_fatalx!(
                        b"%s: %s\0" as *const u8 as *const libc::c_char,
                        get_function_name!(),
                        b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                    );
                }
                sessions_size = (sessions_size as libc::c_ulong)
                    .wrapping_mul(2 as libc::c_int as libc::c_ulong)
                    as size_t as size_t;
            }

            let fresh1 = &mut *sessions.offset(sessions_len as isize);
            *fresh1 = strdup(((*dp).d_name).as_mut_ptr());
            if (*fresh1).is_null() {
                sudo_fatalx!(
                    b"%s: %s\0" as *const u8 as *const libc::c_char,
                    get_function_name!(),
                    b"unable to allocate memory\0" as *const u8 as *const libc::c_char
                );
            }
            sessions_len = sessions_len.wrapping_add(1);
        }

        closedir(d);
        if !sessions.is_null() {
            qsort(
                sessions as *mut libc::c_void,
                sessions_len,
                ::core::mem::size_of::<*mut libc::c_char>() as libc::c_ulong,
                Some(
                    session_compare
                        as unsafe extern "C" fn(
                            *const libc::c_void,
                            *const libc::c_void,
                        ) -> libc::c_int,
                ),
            );

            i = 0 as libc::c_int as libc::c_uint;
            while (i as libc::c_ulong) < sessions_len {
                len = snprintf(
                    &mut *pathbuf.as_mut_ptr().offset(sdlen as isize) as *mut libc::c_char,
                    (::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong)
                        .wrapping_sub(sdlen),
                    b"%s/log\0" as *const u8 as *const libc::c_char,
                    *sessions.offset(i as isize),
                );
                if len < 0 as libc::c_int
                    || len as size_t
                        >= (::core::mem::size_of::<[libc::c_char; 4096]>() as libc::c_ulong)
                            .wrapping_sub(sdlen)
                {
                    *__errno_location() = ENAMETOOLONG as libc::c_int;
                    sudo_fatalx!(
                        b"%s/%s/log\0" as *const u8 as *const libc::c_char,
                        dir,
                        *sessions.offset(i as isize)
                    );
                }
                free(*sessions.offset(i as isize) as *mut libc::c_void);

                if lstat(pathbuf.as_mut_ptr(), &mut sb) == 0 as libc::c_int
                    && sb.st_mode & 0o170000 as libc::c_int as libc::c_uint
                        == 0o100000 as libc::c_int as libc::c_uint
                {
                    list_session(pathbuf.as_mut_ptr(), re, user, tty);
                } else {
                    pathbuf[sdlen
                        .wrapping_add(len as libc::c_ulong)
                        .wrapping_sub(4 as libc::c_int as libc::c_ulong)
                        as usize] = '\0' as i32 as libc::c_char;
                    if checked_type as libc::c_int != 0
                        || lstat(pathbuf.as_mut_ptr(), &mut sb) == 0 as libc::c_int
                            && sb.st_mode & 0o170000 as libc::c_int as libc::c_uint
                                == 0o40000 as libc::c_int as libc::c_uint
                    {
                        find_sessions(pathbuf.as_mut_ptr(), re, user, tty);
                    }
                }
                i = i.wrapping_add(1);
            } //for
            free(sessions as *mut libc::c_void);
        } //if

        debug_return_int!(0);
    } //unsafe
}

fn list_sessions(
    mut argc: libc::c_int,
    mut argv: *mut *mut libc::c_char,
    mut pattern: *const libc::c_char,
    mut user: *const libc::c_char,
    mut tty: *const libc::c_char,
) -> libc::c_int {
    let mut rebuf: regex_t = regex_t {
        buffer: std::ptr::null_mut::<re_dfa_t>(),
        allocated: 0,
        used: 0,
        syntax: 0,
        fastmap: std::ptr::null_mut::<libc::c_char>(),
        translate: std::ptr::null_mut::<libc::c_uchar>(),
        re_nsub: 0,
        can_be_null_regs_allocated_fastmap_accurate_no_sub_not_bol_not_eol_newline_anchor: [0; 1],
        c2rust_padding: [0; 7],
    };
    let mut re: *mut regex_t = std::ptr::null_mut::<regex_t>();
    unsafe {
        debug_decl!(SUDOERS_DEBUG_UTIL!());

        parse_expr(&mut search_expr, argv, 0 as libc::c_int != 0);
        if !pattern.is_null() {
            re = &mut rebuf;
            if regcomp(re, pattern, REG_EXTENDED | 1 << 3 as libc::c_int) != 0 as libc::c_int {
                sudo_fatalx!(
                    b"invalid regular expression: %s\0" as *const u8 as *const libc::c_char,
                    pattern,
                );
            }
        }
        debug_return_int!(find_sessions(session_dir, re, user, tty));
    } //unsafe
}

unsafe extern "C" fn read_keyboard(
    mut fd: libc::c_int,
    mut what: libc::c_int,
    mut v: *mut libc::c_void,
) {
    let mut closure: *mut replay_closure = v as *mut replay_closure;
    static mut paused: bool = 0 as libc::c_int != 0;
    let mut ts: timespec = timespec {
        tv_sec: 0,
        tv_nsec: 0,
    };
    let mut nread: ssize_t = 0;
    let mut ch: libc::c_char = 0;
    debug_decl!(SUDOERS_DEBUG_UTIL!());

    nread = read(
        fd,
        &mut ch as *mut libc::c_char as *mut libc::c_void,
        1 as libc::c_int as size_t,
    );

    match nread {
        -1 => {
            if *__errno_location() != EINTR as libc::c_int
                && *__errno_location() != EAGAIN as libc::c_int
            {
                sudo_fatalx!(
                    b"unable to read %s\0" as *const u8 as *const libc::c_char,
                    b"stdin\0" as *const u8 as *const libc::c_char,
                );
            }
        }
        0 => {}
        _ => {
            if paused {
                paused = 0 as libc::c_int != 0;
                delay_cb(
                    -(1 as libc::c_int),
                    0x1 as libc::c_int,
                    closure as *mut libc::c_void,
                );
                debug_return!();
            }
            match ch as u8 as char {
                ' ' => {
                    paused = 1 as libc::c_int != 0;
                    sudo_ev_del_v1((*closure).evbase, (*closure).delay_ev);
                }
                '<' => {
                    speed_factor /= 2 as libc::c_int as libc::c_double;
                    sudo_ev_get_timeleft_v2((*closure).delay_ev, &mut ts);
                    if ts.tv_sec != 0 || ts.tv_nsec != 0 {
                        ts.tv_sec *= 2 as libc::c_int as libc::c_long;
                        ts.tv_nsec *= 2 as libc::c_int as libc::c_long;
                        if ts.tv_nsec >= 1000000000 as libc::c_int as libc::c_long {
                            ts.tv_sec += 1;
                            ts.tv_nsec -= 1000000000 as libc::c_int as libc::c_long;
                        }
                        if sudo_ev_add_v2(
                            std::ptr::null_mut::<sudo_event_base>(),
                            (*closure).delay_ev,
                            &mut ts,
                            0 as libc::c_int != 0,
                        ) == -(1 as libc::c_int)
                        {
                            sudo_debug_printf!(
                                SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                                b"failed to double remaining delay timeout\0" as *const u8
                                    as *const libc::c_char
                            );
                        }
                    }
                }
                '>' => {
                    speed_factor *= 2 as libc::c_int as libc::c_double;
                    sudo_ev_get_timeleft_v2((*closure).delay_ev, &mut ts);
                    if ts.tv_sec != 0 || ts.tv_nsec != 0 {
                        if ts.tv_sec & 1 as libc::c_int as libc::c_long != 0 {
                            ts.tv_nsec += 500000000 as libc::c_int as libc::c_long;
                        }
                        ts.tv_sec /= 2 as libc::c_int as libc::c_long;
                        ts.tv_nsec /= 2 as libc::c_int as libc::c_long;
                        if sudo_ev_add_v2(
                            std::ptr::null_mut::<sudo_event_base>(),
                            (*closure).delay_ev,
                            &mut ts,
                            0 as libc::c_int != 0,
                        ) == -(1 as libc::c_int)
                        {
                            sudo_debug_printf!(
                                SUDO_DEBUG_ERROR | SUDO_DEBUG_LINENO,
                                b"failed to halve remaining delay timeout\0" as *const u8
                                    as *const libc::c_char
                            );
                        }
                    }
                }
                '\r' | '\n' => {
                    sudo_ev_del_v1((*closure).evbase, (*closure).delay_ev);
                    delay_cb(
                        -(1 as libc::c_int),
                        0x1 as libc::c_int,
                        closure as *mut libc::c_void,
                    );
                }
                _ => {}
            } //match ch
        } //match nread default
    } //match nread
    debug_return!();
}

unsafe fn usage(mut fatal: libc::c_int) {
    fprintf(
        if fatal != 0 { stderr } else { stdout },
        dcgettext(
            std::ptr::null::<libc::c_char>(),
            b"usage: %s [-hnRS] [-d dir] [-m num] [-s num] ID\n\0" as *const u8
                as *const libc::c_char,
            5 as libc::c_int,
        ),
        sudo_getprogname(),
    );
    fprintf(
        if fatal != 0 { stderr } else { stdout },
        dcgettext(
            std::ptr::null::<libc::c_char>(),
            b"usage: %s [-h] [-d dir] -l [search expression]\n\0" as *const u8
                as *const libc::c_char,
            5 as libc::c_int,
        ),
        sudo_getprogname(),
    );
    if fatal != 0 {
        exit(1 as libc::c_int);
    }
}

unsafe fn help() -> ! {
    println!("utsudoreplay - replay utsudo session logs\n\0");
    usage(0 as libc::c_int);
    puts(
        dcgettext(
            std::ptr::null::<libc::c_char>(),
            b"\nOptions:\n  -d, --directory=dir    specify directory for session logs\n  -f, --filter=filter    specify which I/O type(s) to display\n  -h, --help             display help message and exit\n  -l, --list             list available session IDs, with optional expression\n  -m, --max-wait=num     max number of seconds to wait between events\n  -n, --non-interactive  no prompts, session is sent to the standard output\n  -R, --no-resize        do not attempt to re-size the terminal\n  -S, --suspend-wait     wait while the command was suspended\n  -s, --speed=num        speed up or slow down output\n  -V, --version          display version information and exit\0"
                as *const u8 as *const libc::c_char,
            5 as libc::c_int,
        ),
    );
    exit(0 as libc::c_int);
}
unsafe extern "C" fn sudoreplay_cleanup() {
    restore_terminal_size();
    sudo_term_restore_v1(ttyfd, 0 as libc::c_int != 0);
}
pub fn main() {
    let mut args: Vec<*mut libc::c_char> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::core::ptr::null_mut());
    ::std::process::exit(main_0((args.len() - 1) as libc::c_int, args.as_mut_ptr()) as i32)
}
unsafe extern "C" fn run_static_initializers() {
    search_expr = {
        search_node_list {
            stqh_first: std::ptr::null_mut::<search_node>(),
            stqh_last: &mut search_expr.stqh_first,
        }
        //init
    };
}
#[used]
#[cfg_attr(target_os = "linux", link_section = ".init_array")]
#[cfg_attr(target_os = "windows", link_section = ".CRT$XIB")]
#[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
static INIT_ARRAY: [unsafe extern "C" fn(); 1] = [run_static_initializers];
